|
Embedded SDK
Embedded SDK
|
Dynamic memory allocation API. More...
#include <stdint.h>#include <stdbool.h>#include <stddef.h>

Go to the source code of this file.
Classes | |
| struct | mem_stat_t |
| this structure, filled by mem_stat More... | |
Typedefs | |
| typedef void * | mem_ctx_t |
| type shared externally | |
| typedef bool(* | mem_parse_callback_t) (void *data, uint8_t *addr, bool allocated, size_t size) |
| function called for each chunk found in the heap. | |
Functions | |
| mem_ctx_t | mem_init (void *heap_start, size_t heap_size) |
| initializes the heap for this allocator | |
| void * | mem_alloc (mem_ctx_t ctx, size_t nb_bytes) |
| allocates a buffer of the given size, if possible | |
| void | mem_free (mem_ctx_t ctx, void *ptr) |
| frees the given buffer | |
| void | mem_parse (mem_ctx_t ctx, mem_parse_callback_t callback, void *dat) |
| parse the heap | |
| void | mem_stat (mem_ctx_t *ctx, mem_stat_t *stat) |
| function used to get statistics (nb chunks, nb allocated chunks, total size) about the heap | |
Dynamic memory allocation API.
Definition in file mem_alloc.h.
| typedef void* mem_ctx_t |
type shared externally
Definition at line 27 of file mem_alloc.h.
| typedef bool(* mem_parse_callback_t) (void *data, uint8_t *addr, bool allocated, size_t size) |
function called for each chunk found in the heap.
| data | context data, passed as argument of mem_parse |
| addr | address of the chunk (as returned by mem_alloc) if allocated |
| allocated | if true, means the chunk is allocated |
| size | size of the chunk, in bytes (including header & alignment bytes) |
Definition at line 40 of file mem_alloc.h.
| void * mem_alloc | ( | mem_ctx_t | ctx, |
| size_t | nb_bytes | ||
| ) |
allocates a buffer of the given size, if possible
| ctx | allocator context (returned by mem_init()) |
| nb_bytes | size in bytes of the buffer to allocate (must be > 0) |
Definition at line 320 of file mem_alloc.c.
| void mem_free | ( | mem_ctx_t | ctx, |
| void * | ptr | ||
| ) |
frees the given buffer
| ctx | allocator context (returned by mem_init()) |
| ptr | buffer previously allocated with mem_alloc |
Definition at line 406 of file mem_alloc.c.
| mem_ctx_t mem_init | ( | void * | heap_start, |
| size_t | heap_size | ||
| ) |
initializes the heap for this allocator
| heap_start | address of the heap to use |
| heap_size | size in bytes of the heap to use. It must be a multiple of 8, and at least 200 bytes but less than 32kBytes (max is exactly 32856 bytes) |
Definition at line 283 of file mem_alloc.c.
| void mem_parse | ( | mem_ctx_t | ctx, |
| mem_parse_callback_t | callback, | ||
| void * | data | ||
| ) |
parse the heap
| ctx | allocator context (returned by mem_init()) |
| ptr | buffer previously allocated with mem_alloc |
| data | context data, passed to given callback |
Definition at line 439 of file mem_alloc.c.
| void mem_stat | ( | mem_ctx_t * | ctx, |
| mem_stat_t * | stat | ||
| ) |
function used to get statistics (nb chunks, nb allocated chunks, total size) about the heap
| ctx | allocator context (returned by mem_init()) |
| ptr | buffer previously allocated with mem_alloc |
Definition at line 477 of file mem_alloc.c.