Memory manager

group LWESP_MEM

Dynamic memory manager.

Functions

uint8_t lwesp_mem_assignmemory(const lwesp_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 LWESP_CFG_MEM_CUSTOM is 1

Parameters
  • [in] regions – Pointer to list of regions to use for allocations

  • [in] len – Number of regions to use

Returns

1 on success, 0 otherwise

void *lwesp_mem_malloc(size_t size)

Allocate memory of specific size.

Note

Function is not available when LWESP_CFG_MEM_CUSTOM is 1 and must be implemented by user

Parameters

[in] size – Number of bytes to allocate

Returns

Memory address on success, NULL otherwise

void *lwesp_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 LWESP_CFG_MEM_CUSTOM is 1 and must be implemented by user

Parameters
Returns

Memory address on success, NULL otherwise

void *lwesp_mem_calloc(size_t num, size_t size)

Allocate memory of specific size and set memory to zero.

Note

Function is not available when LWESP_CFG_MEM_CUSTOM is 1 and must be implemented by user

Parameters
  • [in] num – Number of elements to allocate

  • [in] size – Size of each element

Returns

Memory address on success, NULL otherwise

void lwesp_mem_free(void *ptr)

Free memory.

Note

Function is not available when LWESP_CFG_MEM_CUSTOM is 1 and must be implemented by user

Parameters

[in] ptr – Pointer to memory previously returned using lwesp_mem_malloc, lwesp_mem_calloc or lwesp_mem_realloc functions

uint8_t lwesp_mem_free_s(void **ptr)

Free memory in safe way by invalidating pointer after freeing.

Parameters

[in] ptr – Pointer to pointer to allocated memory to free

Returns

1 on success, 0 otherwise

struct lwesp_mem_region_t
#include <lwesp_mem.h>

Single memory region descriptor.

Public Members

void *start_addr

Start address of region

size_t size

Size in units of bytes of region