/allocator

library to allocate from a pool, written in C, which should integrate with some of my other libraries

Primary LanguageC

THIS LIBRARY IS A WORK IN PROGRESS

This is a (small) library for creating arenas to allocate within, which will allow you to limit the amount of memory to a library (assuming the library handles out of memory conditions correctly) or module within an embedded system.

The users of this library should not use malloc, calloc or realloc, but instead should use a function with the following type:

typedef void *(*allocator_fn)(void *arena, void *ptr, size_t oldsz, size_t newsz);

Provided by:

void *allocator(void *arena, void *ptr, size_t oldsz, size_t newsz);

In this library.

The single function is capable of allocating, reallocating, and freeing memory. Your library should accept an allocator_fn as a callback with a pointer to an arena.

This allocator library also provides more details than the standard allocation routines in C.

Libraries of mine that use the allocator_fn are:

When allocation is used within a library you should try to avoid using the built in allocation routines, this will in part allow the library to be used on embedded devices, or make it more likely to be (or better still, allocate everything upfront, allow the library user to specify where the allocation takes place, or just eliminate as much dynamic allocation as possible).