amino
1.0-beta2
Lightweight Robot Utility Library
|
Data Structure for Region-Based memory allocation. More...
#include <mem.h>
Public Attributes | |
uint8_t * | head |
pointer to first free element of top chunk | |
struct aa_mem_region_node * | node |
linked list of chunks | |
union { | |
int reserved | |
Reserve space for other bits. | |
struct { | |
unsigned free_on_destroy | |
Free struct when calling aa_mem_region_destroy(). More... | |
} | |
}; | |
Data Structure for Region-Based memory allocation.
Memory regions provide fast allocation of individual objects and fast deallocation of all objects in the region and of all objects allocated after some given object. It is not possible to deallocate only a single arbitrary object from the region.
This provides two benefits over malloc/free. First, as long as the requested allocation can be fulfilled from the memory available in the region, allocation and deallocation require only a pointer increment or decrement. Second, there is no need to store any metadata for each individual allocation resulting in some space savings, expecially for small objects.
This implementation pre-allocates chunks of memory and fulfills individual requests from those chunks. If the request cannot be satisfied from the currently available chunk, this implemention will malloc() another chunk and add it to the region in a linked list. When objects are deallocated via a release or a pop, chunks are merged into one, possibly requiring several calls to free() followed by a single malloc of a new, larger chunk.
unsigned aa_mem_region::free_on_destroy |
Free struct when calling aa_mem_region_destroy().
This bit is set by either aa_mem_region_init() or aa_mem_region_create().