Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
app_mem_utils.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdbool.h>
4#include <stdlib.h>
5#include <stdint.h>
6
7#ifdef HAVE_MEMORY_PROFILING
8#define ALLOC_FILE __FILE__
9#define ALLOC_LINE __LINE__
10#else
11#define ALLOC_FILE NULL
12#define ALLOC_LINE 0
13#endif
14
15// Utility wrappers to handle file and line info automatically (for profiling)
16#define APP_MEM_ALLOC(size) mem_utils_alloc(size, false, ALLOC_FILE, ALLOC_LINE)
17#define APP_MEM_REALLOC(ptr, size) mem_utils_realloc(ptr, size, ALLOC_FILE, ALLOC_LINE)
18#define APP_MEM_FREE(ptr) mem_utils_free(ptr, ALLOC_FILE, ALLOC_LINE)
19#define APP_MEM_FREE_AND_NULL(ptr) mem_utils_free_and_null(ptr, ALLOC_FILE, ALLOC_LINE)
20#define APP_MEM_STRDUP(ptr) mem_utils_strdup(ptr, ALLOC_FILE, ALLOC_LINE)
21#define APP_MEM_CALLOC(ptr, size) mem_utils_calloc(ptr, size, false, ALLOC_FILE, ALLOC_LINE)
22#define APP_MEM_PERMANENT(ptr, size) mem_utils_calloc(ptr, size, true, ALLOC_FILE, ALLOC_LINE)
23
24bool mem_utils_init(void *heap_start, size_t heap_size);
25void *mem_utils_alloc(size_t size, bool permanent, const char *file, int line);
26void *mem_utils_realloc(void *ptr, size_t size, const char *file, int line);
27void mem_utils_free(void *ptr, const char *file, int line);
28void mem_utils_free_and_null(void **buffer, const char *file, int line);
29char *mem_utils_strdup(const char *s, const char *file, int line);
30bool mem_utils_calloc(void **buffer, uint16_t size, bool permanent, const char *file, int line);
void * mem_utils_realloc(void *ptr, size_t size, const char *file, int line)
Internal implementation of memory reallocation.
void mem_utils_free_and_null(void **buffer, const char *file, int line)
Internal implementation of safe free with nullification.
char * mem_utils_strdup(const char *s, const char *file, int line)
Internal implementation of string duplication.
bool mem_utils_init(void *heap_start, size_t heap_size)
Initializes the App heap buffer.
void * mem_utils_alloc(size_t size, bool permanent, const char *file, int line)
Internal implementation of memory allocation.
void mem_utils_free(void *ptr, const char *file, int line)
Internal implementation of memory free.
bool mem_utils_calloc(void **buffer, uint16_t size, bool permanent, const char *file, int line)
Internal implementation of memory allocation of a zero-initialized buffer freeing any existing alloca...