Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
mem_alloc.h
Go to the documentation of this file.
1
7#pragma once
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13/*********************
14 * INCLUDES
15 *********************/
16#include <stdint.h>
17#include <stdbool.h>
18#include <stddef.h>
19
20/**********************
21 * TYPEDEFS
22 **********************/
27typedef void *mem_ctx_t;
28
40typedef bool (*mem_parse_callback_t)(void *data, uint8_t *addr, bool allocated, size_t size);
41
46typedef struct {
47 size_t total_size;
48 size_t free_size;
51 uint32_t nb_chunks;
52 uint32_t nb_allocated;
54
55/**********************
56 * GLOBAL PROTOTYPES
57 **********************/
58
59mem_ctx_t mem_init(void *heap_start, size_t heap_size);
60void *mem_alloc(mem_ctx_t ctx, size_t nb_bytes);
61void mem_free(mem_ctx_t ctx, void *ptr);
62void mem_parse(mem_ctx_t ctx, mem_parse_callback_t callback, void *dat);
63void mem_stat(mem_ctx_t *ctx, mem_stat_t *stat);
64
65#ifdef __cplusplus
66} /* extern "C" */
67#endif
void * mem_ctx_t
type shared externally
Definition mem_alloc.h:27
bool(* mem_parse_callback_t)(void *data, uint8_t *addr, bool allocated, size_t size)
function called for each chunk found in the heap.
Definition mem_alloc.h:40
mem_ctx_t mem_init(void *heap_start, size_t heap_size)
initializes the heap for this allocator
Definition mem_alloc.c:283
void * mem_alloc(mem_ctx_t ctx, size_t nb_bytes)
allocates a buffer of the given size, if possible
Definition mem_alloc.c:320
void mem_parse(mem_ctx_t ctx, mem_parse_callback_t callback, void *dat)
parse the heap
Definition mem_alloc.c:439
void mem_free(mem_ctx_t ctx, void *ptr)
frees the given buffer
Definition mem_alloc.c:406
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
Definition mem_alloc.c:477
this structure, filled by mem_stat
Definition mem_alloc.h:46
size_t allocated_size
nb bytes allocated in the heap (including headers)
Definition mem_alloc.h:50
size_t total_size
total size of the heap (including allocator internal data)
Definition mem_alloc.h:47
uint32_t nb_allocated
number of allocated chunks
Definition mem_alloc.h:52
size_t free_size
Definition mem_alloc.h:48
uint32_t nb_chunks
total number of chunks
Definition mem_alloc.h:51
unsigned char uint8_t
Definition usbd_conf.h:53