void *ei_malloc(size_t size);

Brief: Wrapper around malloc

Location: edge-impulse-sdk/porting/ei_classifier_porting.h

Blocking: Depends on user implementation

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);


  • size - [input] Number of bytes to allocate

Pointer to the allocated memory. Should return NULL if there was an error allocating memory.

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: