Up: Generic Constructs [Index]
The memory allocator construct defines some memory allocation mean. It describe some memory allocation context, some memory allocation method, some memory reallocation method and some memory deallocation method.
the memory allocation context is some 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 some memory segment of some specified size.
It is declared as:
int (*link)(void *, void **, unsigned);
It is pass 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 some memory segment to some specified size.
It is declared as:
int (*mode)(void *, void **, unsigned);
It is pass 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 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 pass 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.
Up: Generic Constructs [Index]