Embedded Artistry libmemory
Memory library for embedded systems (malloc and friends)
|
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "aligned_malloc.h"
#include "malloc.h"
Go to the source code of this file.
Macros | |
#define | align_up(num, align) (((num) + ((align)-1)) & ~((align)-1)) |
#define | PTR_OFFSET_SZ sizeof(offset_t) |
Macro for accessing the size of our current pointer offset. More... | |
Typedefs | |
typedef uint16_t | offset_t |
Number of bytes we're using for storing the aligned pointer offset. More... | |
Functions | |
void * | aligned_malloc (size_t align, size_t size) |
Allocated aligned memory. More... | |
void | aligned_free (void *ptr) |
Free aligned memory. More... | |
#define align_up | ( | num, | |
align | |||
) | (((num) + ((align)-1)) & ~((align)-1)) |
Simple macro for making sure memory addresses are aligned to the nearest power of two
Definition at line 21 of file aligned_malloc.c.
#define PTR_OFFSET_SZ sizeof(offset_t) |
Macro for accessing the size of our current pointer offset.
Definition at line 28 of file aligned_malloc.c.
typedef uint16_t offset_t |
Number of bytes we're using for storing the aligned pointer offset.
Definition at line 25 of file aligned_malloc.c.
void aligned_free | ( | void * | ptr | ) |
Free aligned memory.
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.
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().