universe@390:
universe@390:
universe@390:
universe@390:
universe@390: |
universe@390:
universe@390: ucx
universe@390:
universe@390: UAP Common Extensions
universe@390: |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
Allocator for custom memory management.
universe@390: More...
universe@390:
#include "ucx.h"
universe@390:
universe@390:
Go to the source code of this file.
universe@390:
universe@390: |
universe@390: struct | UcxAllocator |
universe@390: | UCX allocator data structure containing memory management functions. More...
|
universe@390: |
universe@390:
universe@390: |
universe@390: #define | almalloc(allocator, n) ((allocator)->malloc((allocator)->pool, n)) |
universe@390: | Shorthand for calling an allocators malloc function. More...
|
universe@390: |
universe@390: #define | alcalloc(allocator, n, size) ((allocator)->calloc((allocator)->pool, n, size)) |
universe@390: | Shorthand for calling an allocators calloc function. More...
|
universe@390: |
universe@390: #define | alrealloc(allocator, ptr, n) ((allocator)->realloc((allocator)->pool, ptr, n)) |
universe@390: | Shorthand for calling an allocators realloc function. More...
|
universe@390: |
universe@390: #define | alfree(allocator, ptr) ((allocator)->free((allocator)->pool, ptr)) |
universe@390: | Shorthand for calling an allocators free function. More...
|
universe@390: |
universe@390: #define | UCX_ALLOCATOR_DEFAULT |
universe@390: | Convenient macro for a default allocator struct definition. More...
|
universe@390: |
universe@390:
universe@390: |
universe@390: typedef void *(* | ucx_allocator_malloc) (void *pool, size_t n) |
universe@390: | A function pointer to the allocators malloc() function. More...
|
universe@390: |
universe@390: typedef void *(* | ucx_allocator_calloc) (void *pool, size_t n, size_t size) |
universe@390: | A function pointer to the allocators calloc() function. More...
|
universe@390: |
universe@390: typedef void *(* | ucx_allocator_realloc) (void *pool, void *data, size_t n) |
universe@390: | A function pointer to the allocators realloc() function. More...
|
universe@390: |
universe@390: typedef void(* | ucx_allocator_free) (void *pool, void *data) |
universe@390: | A function pointer to the allocators free() function. More...
|
universe@390: |
universe@390:
universe@390: |
universe@390: UcxAllocator * | ucx_default_allocator () |
universe@390: | Returns a pointer to the default allocator. More...
|
universe@390: |
universe@390: void * | ucx_default_malloc (void *ignore, size_t n) |
universe@390: | A wrapper for the standard libc malloc() function. More...
|
universe@390: |
universe@390: void * | ucx_default_calloc (void *ignore, size_t n, size_t size) |
universe@390: | A wrapper for the standard libc calloc() function. More...
|
universe@390: |
universe@390: void * | ucx_default_realloc (void *ignore, void *data, size_t n) |
universe@390: | A wrapper for the standard libc realloc() function. More...
|
universe@390: |
universe@390: void | ucx_default_free (void *ignore, void *data) |
universe@390: | A wrapper for the standard libc free() function. More...
|
universe@390: |
universe@390:
universe@390:
universe@390:
Allocator for custom memory management.
universe@390:
A UCX allocator consists of a pointer to the memory area / pool and four function pointers to memory management functions operating on this memory area / pool. These functions shall behave equivalent to the standard libc functions malloc(), calloc(), realloc()
and free()
.
universe@390:
The signature of the memory management functions is based on the signature of the respective libc function but each of them takes the pointer to the memory area / pool as first argument.
universe@390:
As the pointer to the memory area / pool can be arbitrarily chosen, any data can be provided to the memory management functions. A UcxMempool is just one example.
universe@390:
- See also
- mempool.h
universe@390: -
universe@390: UcxMap
universe@390:
- Author
- Mike Becker
universe@390: -
universe@390: Olaf Wintermann
universe@390:
universe@390:
universe@390:
◆ alcalloc
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: #define alcalloc |
universe@390: ( |
universe@390: |
universe@390: allocator, |
universe@390:
universe@390:
universe@390: |
universe@390: |
universe@390: |
universe@390: n, |
universe@390:
universe@390:
universe@390: |
universe@390: |
universe@390: |
universe@390: size |
universe@390:
universe@390:
universe@390: |
universe@390: ) |
universe@390: | ((allocator)->calloc((allocator)->pool, n, size)) |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
Shorthand for calling an allocators calloc function.
universe@390:
- Parameters
-
universe@390:
universe@390: allocator | the allocator to use |
universe@390: n | the count of elements the space should be allocated for |
universe@390: size | the size of each element |
universe@390:
universe@390:
universe@390:
universe@390:
- Returns
- a pointer to the allocated memory area
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
◆ alfree
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: #define alfree |
universe@390: ( |
universe@390: |
universe@390: allocator, |
universe@390:
universe@390:
universe@390: |
universe@390: |
universe@390: |
universe@390: ptr |
universe@390:
universe@390:
universe@390: |
universe@390: ) |
universe@390: | ((allocator)->free((allocator)->pool, ptr)) |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
Shorthand for calling an allocators free function.
universe@390:
- Parameters
-
universe@390:
universe@390: allocator | the allocator to use |
universe@390: ptr | the pointer to the memory area that shall be freed |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
◆ almalloc
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: #define almalloc |
universe@390: ( |
universe@390: |
universe@390: allocator, |
universe@390:
universe@390:
universe@390: |
universe@390: |
universe@390: |
universe@390: n |
universe@390:
universe@390:
universe@390: |
universe@390: ) |
universe@390: | ((allocator)->malloc((allocator)->pool, n)) |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
Shorthand for calling an allocators malloc function.
universe@390:
- Parameters
-
universe@390:
universe@390: allocator | the allocator to use |
universe@390: n | size of space to allocate |
universe@390:
universe@390:
universe@390:
universe@390:
- Returns
- a pointer to the allocated memory area
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
◆ alrealloc
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: #define alrealloc |
universe@390: ( |
universe@390: |
universe@390: allocator, |
universe@390:
universe@390:
universe@390: |
universe@390: |
universe@390: |
universe@390: ptr, |
universe@390:
universe@390:
universe@390: |
universe@390: |
universe@390: |
universe@390: n |
universe@390:
universe@390:
universe@390: |
universe@390: ) |
universe@390: | ((allocator)->realloc((allocator)->pool, ptr, n)) |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
Shorthand for calling an allocators realloc function.
universe@390:
- Parameters
-
universe@390:
universe@390: allocator | the allocator to use |
universe@390: ptr | the pointer to the memory area that shall be reallocated |
universe@390: n | the new size of the allocated memory area |
universe@390:
universe@390:
universe@390:
universe@390:
- Returns
- a pointer to the reallocated memory area
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
◆ UCX_ALLOCATOR_DEFAULT
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: #define UCX_ALLOCATOR_DEFAULT |
universe@390:
universe@390:
universe@390:
universe@390:
Value:{NULL, \
ucx_default_free }
void * ucx_default_calloc(void *ignore, size_t n, size_t size)
A wrapper for the standard libc calloc() function.
Definition: allocator.c:50
universe@390:
void * ucx_default_realloc(void *ignore, void *data, size_t n)
A wrapper for the standard libc realloc() function.
Definition: allocator.c:54
universe@390:
universe@390:
Convenient macro for a default allocator struct
definition.
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
◆ ucx_allocator_calloc
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: typedef void*(* ucx_allocator_calloc) (void *pool, size_t n, size_t size) |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
A function pointer to the allocators calloc()
function.
universe@390:
- See also
- UcxAllocator
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
◆ ucx_allocator_free
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: typedef void(* ucx_allocator_free) (void *pool, void *data) |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
A function pointer to the allocators free()
function.
universe@390:
- See also
- UcxAllocator
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
◆ ucx_allocator_malloc
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: typedef void*(* ucx_allocator_malloc) (void *pool, size_t n) |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
A function pointer to the allocators malloc()
function.
universe@390:
- See also
- UcxAllocator
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
◆ ucx_allocator_realloc
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: typedef void*(* ucx_allocator_realloc) (void *pool, void *data, size_t n) |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
A function pointer to the allocators realloc()
function.
universe@390:
- See also
- UcxAllocator
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
◆ ucx_default_allocator()
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: UcxAllocator* ucx_default_allocator |
universe@390: ( |
universe@390: | ) |
universe@390: |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
Returns a pointer to the default allocator.
universe@390:
The default allocator contains wrappers to the standard libc memory management functions. Use this function to get a pointer to a globally available allocator. You may also define an own UcxAllocator by assigning UCX_ALLOCATOR_DEFAULT to a variable and pass the address of this variable to any function that takes a UcxAllocator as argument. Note that using this function is the recommended way of passing a default allocator, thus it never runs out of scope.
universe@390:
- Returns
- a pointer to the default allocator
universe@390:
- See also
- UCX_ALLOCATOR_DEFAULT
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
◆ ucx_default_calloc()
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: void* ucx_default_calloc |
universe@390: ( |
universe@390: void * |
universe@390: ignore, |
universe@390:
universe@390:
universe@390: |
universe@390: |
universe@390: size_t |
universe@390: n, |
universe@390:
universe@390:
universe@390: |
universe@390: |
universe@390: size_t |
universe@390: size |
universe@390:
universe@390:
universe@390: |
universe@390: ) |
universe@390: | |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
A wrapper for the standard libc calloc()
function.
universe@390:
- Parameters
-
universe@390:
universe@390: ignore | ignored (may be used by allocators for pooled memory) |
universe@390: n | argument passed to calloc() |
universe@390: size | argument passed to calloc() |
universe@390:
universe@390:
universe@390:
universe@390:
- Returns
- return value of
calloc()
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
◆ ucx_default_free()
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: void ucx_default_free |
universe@390: ( |
universe@390: void * |
universe@390: ignore, |
universe@390:
universe@390:
universe@390: |
universe@390: |
universe@390: void * |
universe@390: data |
universe@390:
universe@390:
universe@390: |
universe@390: ) |
universe@390: | |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
A wrapper for the standard libc free()
function.
universe@390:
- Parameters
-
universe@390:
universe@390: ignore | ignored (may be used by allocators for pooled memory) |
universe@390: data | argument passed to free() |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
◆ ucx_default_malloc()
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: void* ucx_default_malloc |
universe@390: ( |
universe@390: void * |
universe@390: ignore, |
universe@390:
universe@390:
universe@390: |
universe@390: |
universe@390: size_t |
universe@390: n |
universe@390:
universe@390:
universe@390: |
universe@390: ) |
universe@390: | |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
A wrapper for the standard libc malloc()
function.
universe@390:
- Parameters
-
universe@390:
universe@390: ignore | ignored (may be used by allocators for pooled memory) |
universe@390: n | argument passed to malloc() |
universe@390:
universe@390:
universe@390:
universe@390:
- Returns
- return value of
malloc()
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
◆ ucx_default_realloc()
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: void* ucx_default_realloc |
universe@390: ( |
universe@390: void * |
universe@390: ignore, |
universe@390:
universe@390:
universe@390: |
universe@390: |
universe@390: void * |
universe@390: data, |
universe@390:
universe@390:
universe@390: |
universe@390: |
universe@390: size_t |
universe@390: n |
universe@390:
universe@390:
universe@390: |
universe@390: ) |
universe@390: | |
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
A wrapper for the standard libc realloc()
function.
universe@390:
- Parameters
-
universe@390:
universe@390: ignore | ignored (may be used by allocators for pooled memory) |
universe@390: data | argumend passed to realloc() |
universe@390: n | argument passed to realloc() |
universe@390:
universe@390:
universe@390:
universe@390:
- Returns
- return value of
realloc()
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390:
universe@390: