Embedded Multicore Building Blocks V1.0.0
|
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... | |
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.
void* embb_alloc | ( | size_t | size | ) |
Allocates size
bytes of memory.
Keeps track of allocated memory in debug mode.
size+3*sizeof(size_t)
bytes in debug mode, otherwise size
bytes[in] | size | Size 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.
ptr
is not NULL.[in,out] | ptr | Pointer 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.
size(void*)
. alignment
.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.size
bytes are requested using the functions provided by the operating systems.[in] | alignment | Alignment in bytes |
[in] | size | Size 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.
[in] | size | Size 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.
ptr
is not NULL and was allocated by an aligned method.[in,out] | ptr | Pointer 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.