Embedded Artistry libmemory
Memory library for embedded systems (malloc and friends)
|
#include <stddef.h>
Go to the source code of this file.
Macros | |
#define | memalign(align, size) aligned_malloc(align, size) |
A convenience macro for the Linux API. More... | |
Functions | |
void * | aligned_malloc (size_t align, size_t size) |
Allocated aligned memory. More... | |
int | posix_memalign (void **memptr, size_t alignment, size_t size) |
void | aligned_free (void *ptr) |
Free aligned memory. More... | |
#define memalign | ( | align, | |
size | |||
) | aligned_malloc(align, size) |
A convenience macro for the Linux API.
memalign() is simply a convenience definition which provides the commonly-used Linux API memalign. This forwards the arguments to aligned_malloc() and behaves in the same manner.
align | Alignment of the memory block. Alignment refers to the starting address of the memory block. If 32-byte alignment is requested, the start address of the returned pointer will be 32-byte aligned. Note: Alignment must be a power of two. (1, 2, 4, 8, etc.) |
size | Size of the memory allocation |
Definition at line 57 of file aligned_malloc.h.
void aligned_free | ( | void * | ptr | ) |
Free aligned memory.
Free memory that was allocated using aligned_malloc(). This function must not be called on memory which was not allocated with aligned_malloc().
ptr | Pointer to the aligned_memory() block that will be freed. |
aligned_free works like free(), but we work backwards from the returned pointer to find the correct offset and pointer location to return to free() Note that it is VERY BAD to call free() on an aligned_malloc() pointer.
Definition at line 74 of file aligned_malloc.c.
References free().
void* aligned_malloc | ( | size_t | align, |
size_t | size | ||
) |
Allocated aligned memory.
Allocate memory with at least alignment align
and size size
Memory which has been allocated with aligned_malloc() must be freed by calling aligned_free(). Calling free() will result in a panic or other negative effects.
align | Alignment of the memory block. Alignment refers to the starting address of the memory block. If 32-byte alignment is requested, the start address of the returned pointer will be 32-byte aligned. Note: Alignment must be a power of two. (1, 2, 4, 8, etc.) |
size | Size of the memory allocation |
We will call malloc with extra bytes for our header and the offset required to guarantee the desired alignment.
Definition at line 36 of file aligned_malloc.c.
References align_up, malloc(), and PTR_OFFSET_SZ.
Referenced by posix_memalign().
int posix_memalign | ( | void ** | memptr, |
size_t | alignment, | ||
size_t | size | ||
) |
Posix Memory Alignment Extension
Generated aligned memory. This function forwards the request to aligned malloc. Allocated memory must be freed with aligned_free().
memptr | A pointer to the pointer which will store the aligned memory. The memory must be freed with aligned_free(). memptr must not be NULL. |
alignment | The target alignment for the memory. Must be a power of 2. |
size | The size of the allocation. Must be > 0. |
memptr
is not NULL. alignment
is power-of-2. size
> 0.Definition at line 8 of file posix_memalign.c.
References aligned_malloc(), and IS_POWER_2.