Next: Temporaries Allocator Construct, Previous: Error Reporter Construct, Up: Generic Constructs [Index]
The memory allocator construct defines a memory allocation mean. It describe a memory allocation context, a memory allocation method, a memory reallocation method and a memory deallocation method.
the memory allocation context is the pointer passed as first argument to the memory allocation methods
It is declared as:
void *context;
or:
void *data;
the method is expected to allocate a memory segment of some specified size.
It is declared as:
int (*link)(void *, void **, unsigned);
It is passed the memory allocator context, some address to store the address of the newly allocated memory segment at and the minimum size (expressed in bytes) of the memory segment to allocate that will make it usable as arguments, in this order.
The method is expected to return 0
for success, non zero for failure.
the method is expected to reallocate a memory segment to some specified size.
It is declared as:
int (*mode)(void *, void **, unsigned);
It is passed the memory allocator context, the address at which the address of the memory segment to reallocate is stored and at which the address of the reallocated memory segment is to be stored at and the minimum size (expressed in bytes) of the memory segment to reallocate that will make it usable as arguments, in this order.
The method is not required to recognize NULL
for the segment to
reallocate as not yet allocated and its users will not depends on such
behavior.
The method is expected to return 0
for success, non zero for failure.
the method is expected to deallocate some allocated memory segment.
It is declared as:
int (*free)(void *, void *);
It is passed the memory allocator context and the address of the memory segment to deallocate as arguments, in this order.
The method is expected to return 0
for success, non zero for failure.
Next: Temporaries Allocator Construct, Previous: Error Reporter Construct, Up: Generic Constructs [Index]