/memorymanagement

A little memory management library in C

Primary LanguageCMIT LicenseMIT

memorymanagement

A little library in C for managing memory based on a reference counting system.

Documentation

This project uses doxygen (http://www.stack.nl/~dimitri/doxygen/index.html) for the code documentation. Just point doxygen to the doc/Doxyfile and the html documentation will be generated.

Command line exemple :

cd doc
doxygen Doxyfile

Now open the file html/index.html

Build

Using makefile

Use make directly in the root of the project. The resulting files will be placed in the directory lib.

Using cmake

mkdir build
cd build
cmake ..
make -j
make install

Usage

  1. Allocate a structure with memory management enabled:
struct mystruct *ms = MEMORY_MANAGEMENT_ALLOC(sizeof(struct mystruct));
  1. Optionnaly specify a dealloc (cleanup) function:
MEMORY_MANAGEMENT_ATTRIBUTE_SET_DEALLOC_FUNCTION(mystruct, deallocf);
  1. When you want to become an owner of this strucure:
retain(mystruct);
  1. When you are finished with it:
release(mystruct);

If the reference count hits 0 with this call then the dealloc function (if you specified any) will be called and then the structure will be freed.