Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
Functions
app_mem_utils.c File Reference
#include <stdint.h>
#include <string.h>
#include "os_helpers.h"
#include "os_print.h"
#include "mem_alloc.h"
#include "app_mem_utils.h"
Include dependency graph for app_mem_utils.c:

Go to the source code of this file.

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.
 
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.
 
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 *src, const char *file, int line)
 Internal implementation of string duplication.
 

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.