elpekenin/utils/allocator.h

Utilities to use custom allocators instead of stdlib’s implementation.

This is: malloc(), free(), calloc() and realloc().


type malloc_fn
[source]

Signature of a malloc() function.

type free_fn
[source]

Signature of a free() function.

type calloc_fn
[source]

Signature of a calloc() function.

type realloc_fn
[source]

Signature of a realloc() function.


struct allocator_t
[source]

Information about a custom allocator.

malloc_fn malloc
[source]

Pointer to its malloc implementation.

free_fn free
[source]

Pointer to its free implementation.

calloc_fn calloc
[source]

Pointer to its calloc implementation.

realloc_fn realloc
[source]

Pointer to its realloc implementation.

size_t used
[source]

Memory it has current allocated.

const char *name
[source]

A short name/description.

void *arg
[source]

Arbitrary config used by allocator. Eg a ChibiOS’ pool.

Caution

These wrappers add some extra logic as well as calling allocator->function(args).

Use them instead of manually executing the functions.

void *malloc_with(allocator_t *allocator, size_t total_size)
[source]

Run malloc’s implementation of the given allocator.

void free_with(allocator_t *allocator, void *ptr)
[source]

Run free’s implementation of the given allocator.

void *calloc_with(allocator_t *allocator, size_t nmemb, size_t size)
[source]

Run calloc’s implementation of the given allocator.

void *realloc_with(allocator_t *allocator, void *ptr, size_t size)
[source]

Run realloc’s implementation of the given allocator.


size_t get_used_heap(void)
[source]

Total heap used between all allocators.

const allocator_t **get_known_allocators(int8_t *n)
[source]

Get a pointer to every allocator implementation.

n will be set to the number of allocators.

allocator_t *get_default_allocator(void)
[source]

Get the allocator defined as “default”.


extern allocator_t c_runtime_allocator
[source]

C’s stdlib allocator.

extern allocator_t ch_core_allocator
[source]

ChibiOS’ core allocator.

allocator_t new_ch_pool_allocator(memory_pool_t *pool, const char *name)
[source]

Create a new ChibiOS’ pool allocator.

allocator_t new_ch_heap_allocator(memory_heap_t *heap, const char *name)
[source]

Create a new ChibiOS’ heap allocator.