Next: , Up: allocators   [Contents][Index]


3.1 Type definitions

Struct Typedef: ccmem_allocator_t

Type of struct representing a memory allocator. It has the following fields:

ccmem_allocator_methods_t const * const methods

Pointer to a table of methods representing the behaviour of this allocator.

Instances of this type are meant to be wrapped in other struct to add state to the allocator. For example:

typedef struct my_allocator_t   my_allocator_t;

struct my_allocator_t {
  ccmem_allocator_t     base;
  void *                state;
}
Struct Typedef: ccmem_allocator_methods_t

Type of struct representing the methods of a memory allocator. It has the following fields:

ccmem_malloc_fun_t * const malloc

Pointer to function that allocates memory in a way similar to the standard malloc().

ccmem_realloc_fun_t * const realloc

Pointer to function that reallocates memory in a way similar to the standard realloc().

ccmem_calloc_fun_t * const calloc

Pointer to function that allocates memory in a way similar to the standard calloc().

ccmem_free_fun_t * const free

Pointer to function that releases memory in a way similar to the standard free().

Function: void * ccmem_malloc_fun_t (cce_destination_t L, ccmem_allocator_t const * const A, size_t size)

Type of function that allocates memory in a way similar to the standard malloc(). The function uses the allocator A. If an error occurs: an exception is raised by jumping to the location L. Functions of this type never return NULL.

Function: void * ccmem_realloc_fun_t (cce_destination_t L, ccmem_allocator_t const * const A, void * ptr, size_t newsize)

Type of function that reallocates memory in a way similar to the standard realloc(). The function uses the allocator A. Only memory blocks allocated by A can be reallocated by this function. If an error occurs: an exception is raised by jumping to the location L. Functions of this type never return NULL.

Function: void * ccmem_calloc_fun_t (cce_destination_t L, ccmem_allocator_t const * const A, size_t count, size_t eltsize)

Type of function that allocates memory in a way similar to the standard calloc(). The function uses the allocator A. If an error occurs: an exception is raised by jumping to the location L. Functions of this type never return NULL.

Function: void ccmem_free_fun_t (ccmem_allocator_t const * const A, void * ptr)

Type of function that releases memory in a way similar to the standard free(). The function uses the allocator A. Only memory allocated using the allocator A can be released with this function.

Functions of this type must not raise exceptions. If an allocator fails to release memory: it should mark itself as “in invalid state” and fail to further allocate memory.


Next: , Up: allocators   [Contents][Index]

This document describes version 0.2.2-devel.3 of CCMemory.