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
Note
Function is not available when LWGSM_CFG_MEM_CUSTOM is
1
- Parameters
regions – [in] Pointer to list of regions to use for allocations
len – [in] Number of regions to use
- Returns
1
on success,0
otherwise
-
void *lwgsm_mem_malloc(size_t size)
Allocate memory of specific size.
Note
Function is not available when LWGSM_CFG_MEM_CUSTOM is
1
and must be implemented by user- Parameters
size – [in] Number of bytes to allocate
- Returns
Memory address on success,
NULL
otherwise
-
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
Note
Function is not available when LWGSM_CFG_MEM_CUSTOM is
1
and must be implemented by user- Parameters
ptr – [in] Pointer to current allocated memory to resize, returned using lwgsm_mem_malloc, lwgsm_mem_calloc or lwgsm_mem_realloc functions
size – [in] Number of bytes to allocate on new memory
- Returns
Memory address on success,
NULL
otherwise
-
void *lwgsm_mem_calloc(size_t num, size_t size)
Allocate memory of specific size and set memory to zero.
Note
Function is not available when LWGSM_CFG_MEM_CUSTOM is
1
and must be implemented by user- Parameters
num – [in] Number of elements to allocate
size – [in] Size of each element
- Returns
Memory address on success,
NULL
otherwise
-
void lwgsm_mem_free(void *ptr)
Free memory.
Note
Function is not available when LWGSM_CFG_MEM_CUSTOM is
1
and must be implemented by user- Parameters
ptr – [in] 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.
- Parameters
ptr – [in] Pointer to pointer to allocated memory to free
- Returns
1
on success,0
otherwise
-
struct lwgsm_mem_region_t
- #include <lwgsm_mem.h>
Single memory region descriptor.
-
uint8_t lwgsm_mem_assignmemory(const lwgsm_mem_region_t *regions, size_t size)