eaarl-io
1.0.1+71abbd4
EAARL Input/Output Library (Public API)
|
Memory handler structure. More...
#include <memory.h>
Data Fields | |
void *(* | malloc )(struct eaarlio_memory *self, size_t size) |
Allocate the specified number of bytes. More... | |
void(* | free )(struct eaarlio_memory *self, void *ptr) |
Releases the specified block of memory back to the system. More... | |
void *(* | realloc )(struct eaarlio_memory *self, void *ptr, size_t size) |
Increases or decreases the size of the specified block of memory. More... | |
void *(* | calloc )(struct eaarlio_memory *self, size_t nmemb, size_t size) |
Allocates the specified number of bytes and initializes them to zero. More... | |
void * | opaque |
Internal opaque pointer. More... | |
Memory handler structure.
This structure is designed to closely match the C standard library (stdlib.h) memory functions. The default memory handler (if you provide NULL
as an argument to any function that asks for a memory handler) passes its arguments through to the underlying standard library functions of the same names.
The opaque
field can be used for whatever additional information the caller needs for its internal handling of function calls. If you do not need it, you can set it to NULL
.
Here's a simple illustration of how the memory handler is used within a function:
function example(struct eaarlio_memory *memory) { // Allocate 10 bytes void *data = memory->malloc(memory, 10); }
void*(* eaarlio_memory::calloc) (struct eaarlio_memory *self, size_t nmemb, size_t size) |
Allocates the specified number of bytes and initializes them to zero.
This should have the same behavior as defined for the standard library function calloc.
[in] | self | Pointer to memory handler |
[in] | nmemb | Number of elements in array to allocate |
[in] | size | Size of each element in the array |
NULL
. void(* eaarlio_memory::free) (struct eaarlio_memory *self, void *ptr) |
Releases the specified block of memory back to the system.
This should have the same behavior as defined for the standard library function free.
[in] | self | Pointer to memory handler |
[in] | ptr | Pointer to block of memory to release |
void*(* eaarlio_memory::malloc) (struct eaarlio_memory *self, size_t size) |
Allocate the specified number of bytes.
This should have the same behavior as defined for the standard library function malloc.
[in] | self | Pointer to memory handler |
[in] | size | Bytes to allocate |
NULL
. void* eaarlio_memory::opaque |
Internal opaque pointer.
This is available for use if needed by a memory handler implementation for tracking state or data.
void*(* eaarlio_memory::realloc) (struct eaarlio_memory *self, void *ptr, size_t size) |
Increases or decreases the size of the specified block of memory.
This should have the same behavior as defined for the standard library function realloc.
[in] | self | Pointer to memory handler |
[in] | ptr | Pointer to block of memory to resize |
[in] | size | Bytes to be allocated in the resized block of memory |
NULL
.