ei_malloc()
void *ei_malloc(size_t size);
Brief: Wrapper around malloc
Blocking: Depends on user implementation
Description:
ei_malloc()
is declared internally in the Edge Impulse SDK library, and the function must be defined by the user.This function should allocate
size
bytes and return a pointer to the allocated memory. In bare-metal implementations, it can simply be a wrapper for malloc()
. For example:__attribute__((weak)) void *ei_malloc(size_t size) {
return malloc(size);
}
If you intend to run your impulse in a multi-threaded environment, you will need to ensure that your implementation of
ei_malloc()
is thread-safe. For example, if you are using FreeRTOS, here is one possible implementation:__attribute__((weak)) void *ei_malloc(size_t size) {
return pvPortMalloc(size);
}
Parameters:
size
- [input] Number of bytes to allocate
Returns: Pointer to the allocated memory. Should return
NULL
if there was an error allocating memory.Example: The following examples demonstrate possible implementations of this function for various platforms. Note the
__attribute__((weak))
in most of the definitions, which means that a user could override the implementation elsewhere in the program:Last modified 1yr ago