how to use sys_heap_alloc() stablely?

In my design, many sys_heap_alloc() would be used to push msg(data) to k_fifo.

but, it always return NULL and cause ASSERT..

the following is my code:

#define HEAP_SIZE   4096

static char heap_mem[HEAP_SIZE];
static struct sys_heap heap;
sys_heap_init(&heap, heap_mem, HEAP_SIZE);
In other location:
sys_heap_alloc(&heap, len);
sys_heap_free(&heap, p);
I would call this frequently. sometimes it would works well.
but it return NULL frequently.
how to use the heap_alloc rightly? 
what requirement is need by SIZE?
what requirement is need by len?
alignment?
I have no idea about this.
thanks in advance.
Parents Reply Children
No Data
Related