Skip to content

rustbas/region-based-allocation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TODO

  • Alloc only chars or u8
  • Create STB-style header file
  • Write usage
  • Create examples
  • Fix c89
  • Create 'stack' version (optional)

Description

STB-style library for Region-based memory management. Created for educational purposes.

Usage

You can download repository and run make demo. Is repeats the following information.

To include library (remove #define to include only header part):

#define RB_ALLOC_IMPLEMENTATION
#include "rb_alloc.h"

First of all, you need to initialize region (you may want to redefine REGION_SIZE, default value is 2048 bytes):

Region *region = regionInit(REGION_SIZE);

After that, you work with region like with default malloc:

const size_t ROWS = 3;
const size_t COLS = 4;

double** matrix = regionAlloc(region, sizeof(double*)*ROWS);
for (size_t i = 0; i < ROWS; i++)
  matrix[i] = regionAlloc(region, sizeof(double)*COLS);

After all, you need to free region:

regionFree(region);

For debug purposes you can print region information:

regionDump(region);

It prints all information about region.

References

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors