Embedded Multicore Building Blocks V1.0.0
Functions
Memory Allocation

Functions for dynamic memory allocation. More...

Functions

void * embb_alloc (size_t size)
 Allocates size bytes of memory. More...
 
void embb_free (void *ptr)
 Frees memory that has been allocated by embb_alloc() for some pointer ptr. More...
 
void * embb_alloc_aligned (size_t alignment, size_t size)
 Allocates size bytes of memory with alignment alignment. More...
 
void * embb_alloc_cache_aligned (size_t size)
 Allocates size bytes of cache-aligned memory. More...
 
void embb_free_aligned (void *ptr)
 Frees memory that has been allocated by an aligned method for ptr. More...
 
size_t embb_get_bytes_allocated ()
 Returns the total number of bytes currently allocated. More...
 

Detailed Description

Functions for dynamic memory allocation.

There are functions for aligned and unaligned memory allocation. In debug mode, memory usage is tracked to detect memory leaks.

Function Documentation

void* embb_alloc ( size_t  size)

Allocates size bytes of memory.

Keeps track of allocated memory in debug mode.

Returns
NULL in case of failure, otherwise address of allocated memory block.
Dynamic memory allocation
size+3*sizeof(size_t) bytes in debug mode, otherwise size bytes
Concurrency
Thread-safe
See also
embb_get_bytes_allocated()
Parameters
[in]sizeSize of memory block to be allocated in bytes
void embb_free ( void *  ptr)

Frees memory that has been allocated by embb_alloc() for some pointer ptr.

Keeps track of freed memory in debug mode.

Precondition
ptr is not NULL.
Concurrency
Thread-safe
See also
embb_get_bytes_allocated()
Parameters
[in,out]ptrPointer to memory block to be freed
void* embb_alloc_aligned ( size_t  alignment,
size_t  size 
)

Allocates size bytes of memory with alignment alignment.

This function can be used to align objects to certain boundaries such as cache lines, memory pages, etc.

Keeps track of allocated memory in debug mode.

It is not required that size is a multiple of alignment as, e.g., for the aligned_alloc function of the C11 standard.

Precondition
The alignment has to be power of 2 and a multiple of size(void*).
Postcondition
The returned pointer is a multiple of alignment.
Returns
NULL in case of failure, otherwise address of allocated memory block.
Dynamic memory allocation
Debug mode: Let n be the number of aligned cells necessary to fit the payload. Then, (n+1)*alignment+3*size_of(size_t)-1 bytes are allocated.
Release mode: size bytes are requested using the functions provided by the operating systems.
Concurrency
Thread-safe
Note
Memory allocated using this function must be freed using embb_free_aligned().
See also
embb_alloc_cache_aligned(), embb_free_aligned(), embb_get_bytes_allocated()
Parameters
[in]alignmentAlignment in bytes
[in]sizeSize of memory block to be allocated in bytes
void* embb_alloc_cache_aligned ( size_t  size)

Allocates size bytes of cache-aligned memory.

Specialized version of embb_alloc_aligned(). The alignment is chosen automatically (usually 64 bytes).

Keeps track of allocated memory in debug mode.

Postcondition
The returned pointer is a multiple of the cache line size.
Returns
NULL in case of failure, otherwise address of allocated memory block.
Dynamic memory allocation
See embb_alloc_aligned()
Concurrency
Thread-safe
Note
Memory allocated using this function must be freed using embb_free_aligned().
See also
embb_alloc_aligned(), embb_free_aligned(), embb_get_bytes_allocated()
Parameters
[in]sizeSize of memory block to be allocated in bytes
void embb_free_aligned ( void *  ptr)

Frees memory that has been allocated by an aligned method for ptr.

The available aligned methods are embb_alloc_aligned() or embb_alloc_cache_aligned().

Keeps track of freed memory in debug mode.

Precondition
ptr is not NULL and was allocated by an aligned method.
Concurrency
Thread-safe
See also
embb_alloc_aligned(), embb_alloc_cache_aligned(), embb_get_bytes_allocated()
Parameters
[in,out]ptrPointer to memory block to be freed
size_t embb_get_bytes_allocated ( )

Returns the total number of bytes currently allocated.

Only the bytes allocated by embb_alloc(), embb_alloc_aligned(), and embb_alloc_cache_aligned() in debug mode are counted.

Returns
Number of currently allocated bytes in debug mode, otherwise 0.
Concurrency
Thread-safe and wait-free
See also
embb_alloc(), embb_alloc_aligned(), embb_alloc_cache_aligned()