Memory manager¶
-
group
LWGSM_MEM Dynamic memory manager.
Functions
-
uint8_t
lwgsm_mem_assignmemory(const lwgsm_mem_region_t *regions, size_t size)¶ Assign memory region(s) for allocation functions.
- Note
You can allocate multiple regions by assigning start address and region size in units of bytes
- Return
1on success,0otherwise- Note
Function is not available when LWGSM_CFG_MEM_CUSTOM is
1- Parameters
[in] regions: Pointer to list of regions to use for allocations[in] len: Number of regions to use
-
void *
lwgsm_mem_malloc(size_t size)¶ Allocate memory of specific size.
- Return
Memory address on success,
NULLotherwise- Note
Function is not available when LWGSM_CFG_MEM_CUSTOM is
1and must be implemented by user- Parameters
[in] size: Number of bytes to allocate
-
void *
lwgsm_mem_realloc(void *ptr, size_t size)¶ Reallocate memory to specific size.
- Note
After new memory is allocated, content of old one is copied to new memory
- Return
Memory address on success,
NULLotherwise- Note
Function is not available when LWGSM_CFG_MEM_CUSTOM is
1and must be implemented by user- Parameters
[in] ptr: Pointer to current allocated memory to resize, returned using lwgsm_mem_malloc, lwgsm_mem_calloc or lwgsm_mem_realloc functions[in] size: Number of bytes to allocate on new memory
-
void *
lwgsm_mem_calloc(size_t num, size_t size)¶ Allocate memory of specific size and set memory to zero.
- Return
Memory address on success,
NULLotherwise- Note
Function is not available when LWGSM_CFG_MEM_CUSTOM is
1and must be implemented by user- Parameters
[in] num: Number of elements to allocate[in] size: Size of each element
-
void
lwgsm_mem_free(void *ptr)¶ Free memory.
- Note
Function is not available when LWGSM_CFG_MEM_CUSTOM is
1and must be implemented by user- Parameters
[in] ptr: Pointer to memory previously returned using lwgsm_mem_malloc, lwgsm_mem_calloc or lwgsm_mem_realloc functions
-
uint8_t
lwgsm_mem_free_s(void **ptr)¶ Free memory in safe way by invalidating pointer after freeing.
- Return
1on success,0otherwise- Parameters
[in] ptr: Pointer to pointer to allocated memory to free
-
struct
lwgsm_mem_region_t¶ - #include <lwgsm_mem.h>
Single memory region descriptor.
-
uint8_t