universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: ucx: /home/mike/workspace/c/ucx/src/ucx/allocator.h File Reference 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:
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: Data Structures | universe@390: Macros | universe@390: Typedefs | universe@390: Functions
universe@390:
universe@390:
allocator.h File Reference
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: universe@390: universe@390: universe@390:

universe@390: Data Structures

struct  UcxAllocator
 UCX allocator data structure containing memory management functions. More...
 
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: Macros

#define almalloc(allocator, n)   ((allocator)->malloc((allocator)->pool, n))
 Shorthand for calling an allocators malloc function. More...
 
#define alcalloc(allocator, n, size)   ((allocator)->calloc((allocator)->pool, n, size))
 Shorthand for calling an allocators calloc function. More...
 
#define alrealloc(allocator, ptr, n)   ((allocator)->realloc((allocator)->pool, ptr, n))
 Shorthand for calling an allocators realloc function. More...
 
#define alfree(allocator, ptr)   ((allocator)->free((allocator)->pool, ptr))
 Shorthand for calling an allocators free function. More...
 
#define UCX_ALLOCATOR_DEFAULT
 Convenient macro for a default allocator struct definition. More...
 
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: Typedefs

typedef void *(* ucx_allocator_malloc) (void *pool, size_t n)
 A function pointer to the allocators malloc() function. More...
 
typedef void *(* ucx_allocator_calloc) (void *pool, size_t n, size_t size)
 A function pointer to the allocators calloc() function. More...
 
typedef void *(* ucx_allocator_realloc) (void *pool, void *data, size_t n)
 A function pointer to the allocators realloc() function. More...
 
typedef void(* ucx_allocator_free) (void *pool, void *data)
 A function pointer to the allocators free() function. More...
 
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: Functions

UcxAllocatorucx_default_allocator ()
 Returns a pointer to the default allocator. More...
 
void * ucx_default_malloc (void *ignore, size_t n)
 A wrapper for the standard libc malloc() function. More...
 
void * ucx_default_calloc (void *ignore, size_t n, size_t size)
 A wrapper for the standard libc calloc() function. More...
 
void * ucx_default_realloc (void *ignore, void *data, size_t n)
 A wrapper for the standard libc realloc() function. More...
 
void ucx_default_free (void *ignore, void *data)
 A wrapper for the standard libc free() function. More...
 
universe@390:

Detailed Description

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:

Macro Definition Documentation

universe@390: universe@390:

◆ alcalloc

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:
#define alcalloc( allocator,
 n,
 size 
)   ((allocator)->calloc((allocator)->pool, n, size))
universe@390:
universe@390: universe@390:

Shorthand for calling an allocators calloc function.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
allocatorthe allocator to use
nthe count of elements the space should be allocated for
sizethe size of each element
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: 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:
#define alfree( allocator,
 ptr 
)   ((allocator)->free((allocator)->pool, ptr))
universe@390:
universe@390: universe@390:

Shorthand for calling an allocators free function.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
allocatorthe allocator to use
ptrthe pointer to the memory area that shall be freed
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: 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:
#define almalloc( allocator,
 
)   ((allocator)->malloc((allocator)->pool, n))
universe@390:
universe@390: universe@390:

Shorthand for calling an allocators malloc function.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
allocatorthe allocator to use
nsize of space to allocate
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: 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:
#define alrealloc( allocator,
 ptr,
 
)   ((allocator)->realloc((allocator)->pool, ptr, n))
universe@390:
universe@390: universe@390:

Shorthand for calling an allocators realloc function.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
allocatorthe allocator to use
ptrthe pointer to the memory area that shall be reallocated
nthe new size of the allocated memory area
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: universe@390: universe@390:
#define UCX_ALLOCATOR_DEFAULT
universe@390:
universe@390: Value:
{NULL, \
ucx_default_malloc, ucx_default_calloc, ucx_default_realloc, \
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:

Typedef Documentation

universe@390: universe@390:

◆ ucx_allocator_calloc

universe@390: universe@390:
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:

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: universe@390: universe@390:
typedef void(* ucx_allocator_free) (void *pool, void *data)
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: universe@390: universe@390:
typedef void*(* ucx_allocator_malloc) (void *pool, size_t n)
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: universe@390: universe@390:
typedef void*(* ucx_allocator_realloc) (void *pool, void *data, size_t n)
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:

Function Documentation

universe@390: universe@390:

◆ ucx_default_allocator()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxAllocator* ucx_default_allocator ()
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: 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:
void* ucx_default_calloc (void * ignore,
size_t n,
size_t size 
)
universe@390:
universe@390: universe@390:

A wrapper for the standard libc calloc() function.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
ignoreignored (may be used by allocators for pooled memory)
nargument passed to calloc()
sizeargument passed to calloc()
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: 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:
void ucx_default_free (void * ignore,
void * data 
)
universe@390:
universe@390: universe@390:

A wrapper for the standard libc free() function.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
ignoreignored (may be used by allocators for pooled memory)
dataargument passed to free()
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: 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:
void* ucx_default_malloc (void * ignore,
size_t n 
)
universe@390:
universe@390: universe@390:

A wrapper for the standard libc malloc() function.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
ignoreignored (may be used by allocators for pooled memory)
nargument passed to malloc()
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: 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:
void* ucx_default_realloc (void * ignore,
void * data,
size_t n 
)
universe@390:
universe@390: universe@390:

A wrapper for the standard libc realloc() function.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
ignoreignored (may be used by allocators for pooled memory)
dataargumend passed to realloc()
nargument passed to realloc()
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: