eaarl-io  1.0.1+71abbd4
EAARL Input/Output Library (Public API)
Data Fields
eaarlio_memory Struct Reference

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...
 

Detailed Description

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);
 }
Examples:
memory_stdlib.c.

Field Documentation

◆ calloc

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.

Parameters
[in]selfPointer to memory handler
[in]nmembNumber of elements in array to allocate
[in]sizeSize of each element in the array
Returns
On success, this should return a pointer to the newly allocated memory. On failure, this should return NULL.
Examples:
memory_stdlib.c.

◆ free

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.

Parameters
[in]selfPointer to memory handler
[in]ptrPointer to block of memory to release
Examples:
memory_stdlib.c.

◆ malloc

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.

Parameters
[in]selfPointer to memory handler
[in]sizeBytes to allocate
Returns
On success, this should return a pointer to the newly allocated memory. On failure, this should return NULL.
Examples:
memory_stdlib.c.

◆ opaque

void* eaarlio_memory::opaque

Internal opaque pointer.

This is available for use if needed by a memory handler implementation for tracking state or data.

◆ realloc

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.

Parameters
[in]selfPointer to memory handler
[in]ptrPointer to block of memory to resize
[in]sizeBytes to be allocated in the resized block of memory
Returns
On success, this should return a pointer to the resulting block of memory. On failure, this should return NULL.
Examples:
memory_stdlib.c.

The documentation for this struct was generated from the following file: