Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
Macros | Functions
app_mem_utils.h File Reference
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
Include dependency graph for app_mem_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ALLOC_FILE   NULL
 
#define ALLOC_LINE   0
 
#define APP_MEM_ALLOC(size)   mem_utils_alloc(size, false, ALLOC_FILE, ALLOC_LINE)
 
#define APP_MEM_REALLOC(ptr, size)   mem_utils_realloc(ptr, size, ALLOC_FILE, ALLOC_LINE)
 
#define APP_MEM_FREE(ptr)   mem_utils_free(ptr, ALLOC_FILE, ALLOC_LINE)
 
#define APP_MEM_FREE_AND_NULL(ptr)   mem_utils_free_and_null(ptr, ALLOC_FILE, ALLOC_LINE)
 
#define APP_MEM_STRDUP(ptr)   mem_utils_strdup(ptr, ALLOC_FILE, ALLOC_LINE)
 
#define APP_MEM_CALLOC(ptr, size)   mem_utils_calloc(ptr, size, false, ALLOC_FILE, ALLOC_LINE)
 
#define APP_MEM_PERMANENT(ptr, size)   mem_utils_calloc(ptr, size, true, ALLOC_FILE, ALLOC_LINE)
 

Functions

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_realloc (void *ptr, size_t size, const char *file, int line)
 Internal implementation of memory reallocation.
 
void mem_utils_free (void *ptr, const char *file, int line)
 Internal implementation of memory free.
 
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_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 allocation.
 

Macro Definition Documentation

◆ ALLOC_FILE

#define ALLOC_FILE   NULL

Definition at line 11 of file app_mem_utils.h.

◆ ALLOC_LINE

#define ALLOC_LINE   0

Definition at line 12 of file app_mem_utils.h.

◆ APP_MEM_ALLOC

#define APP_MEM_ALLOC (   size)    mem_utils_alloc(size, false, ALLOC_FILE, ALLOC_LINE)

Definition at line 16 of file app_mem_utils.h.

◆ APP_MEM_CALLOC

#define APP_MEM_CALLOC (   ptr,
  size 
)    mem_utils_calloc(ptr, size, false, ALLOC_FILE, ALLOC_LINE)

Definition at line 21 of file app_mem_utils.h.

◆ APP_MEM_FREE

#define APP_MEM_FREE (   ptr)    mem_utils_free(ptr, ALLOC_FILE, ALLOC_LINE)

Definition at line 18 of file app_mem_utils.h.

◆ APP_MEM_FREE_AND_NULL

#define APP_MEM_FREE_AND_NULL (   ptr)    mem_utils_free_and_null(ptr, ALLOC_FILE, ALLOC_LINE)

Definition at line 19 of file app_mem_utils.h.

◆ APP_MEM_PERMANENT

#define APP_MEM_PERMANENT (   ptr,
  size 
)    mem_utils_calloc(ptr, size, true, ALLOC_FILE, ALLOC_LINE)

Definition at line 22 of file app_mem_utils.h.

◆ APP_MEM_REALLOC

#define APP_MEM_REALLOC (   ptr,
  size 
)    mem_utils_realloc(ptr, size, ALLOC_FILE, ALLOC_LINE)

Definition at line 17 of file app_mem_utils.h.

◆ APP_MEM_STRDUP

#define APP_MEM_STRDUP (   ptr)    mem_utils_strdup(ptr, ALLOC_FILE, ALLOC_LINE)

Definition at line 20 of file app_mem_utils.h.

Function Documentation

◆ mem_utils_alloc()

void * mem_utils_alloc ( size_t  size,
bool  permanent,
const char *  file,
int  line 
)

Internal implementation of memory allocation.

Parameters
[in]sizein bytes to allocate (must be > 0)
[in]permanentif true, the allocation is never freed (for profiling only)
[in]filesource file requesting the allocation (for profiling only)
[in]lineline in the source file requesting the allocation (for profiling only)
Returns
either a valid address if successful, or NULL if failed

Definition at line 48 of file app_mem_utils.c.

◆ mem_utils_calloc()

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 allocation.

Parameters
[out]bufferpointer to the buffer to allocate
[in]size(in bytes) to allocate
[in]permanentif true, the allocation is never freed (for profiling only)
[in]filesource file requesting the allocation (for profiling only)
[in]lineline in the source file requesting the allocation (for profiling only)
Returns
true if the allocation was successful, false otherwise

Definition at line 128 of file app_mem_utils.c.

◆ mem_utils_free()

void mem_utils_free ( void *  ptr,
const char *  file,
int  line 
)

Internal implementation of memory free.

Parameters
[in]ptrpreviously allocated
[in]filesource file requesting the allocation (for profiling only)
[in]lineline in the source file requesting the allocation (for profiling only)

Definition at line 107 of file app_mem_utils.c.

◆ mem_utils_free_and_null()

void mem_utils_free_and_null ( void **  buffer,
const char *  file,
int  line 
)

Internal implementation of safe free with nullification.

Parameters
[in,out]bufferPointer to the buffer to deallocate
[in]filesource file requesting the allocation (for profiling only)
[in]lineline in the source file requesting the allocation (for profiling only)

Definition at line 157 of file app_mem_utils.c.

◆ mem_utils_init()

bool mem_utils_init ( void *  heap_start,
size_t  heap_size 
)

Initializes the App heap buffer.

Parameters
[in]heap_startaddress of the Application heap to use
[in]heap_sizesize in bytes of the heap
Returns
true if successful, false otherwise
Note
Size must be a multiple of 8, and at least 200 B, but less than 32kB

Definition at line 30 of file app_mem_utils.c.

◆ mem_utils_realloc()

void * mem_utils_realloc ( void *  ptr,
size_t  size,
const char *  file,
int  line 
)

Internal implementation of memory reallocation.

Parameters
[in]ptrpreviously allocated or NULL (equivalent to alloc)
[in]sizenew size in bytes to allocate. Can be 0 (equivalent to free).
[in]filesource file requesting the allocation (for profiling only)
[in]lineline in the source file requesting the allocation (for profiling only)
Returns
either a valid address if successful, or NULL if failed or size is 0.

Definition at line 76 of file app_mem_utils.c.

◆ mem_utils_strdup()

char * mem_utils_strdup ( const char *  src,
const char *  file,
int  line 
)

Internal implementation of string duplication.

Parameters
[in]srcstring to duplicate
[in]filesource file requesting the allocation (for profiling only)
[in]lineline in the source file requesting the allocation (for profiling only)
Returns
either a valid address if successful, or NULL if failed

Definition at line 173 of file app_mem_utils.c.