Memory areas provide your application with dynamic allocation of fixed sized memory blocks. Memory areas should be used in preference to the standard C library malloc and free functions if the calling task (or interrupt service routine) cannot block.
You allocate a memory area by declaring it as a C variable
CTL_MEMORY_AREA_t m1;
A message queue is initialised using the ctl_memory_area_init function.
unsigned mem[20]; … ctl_message_queue_init(&m1, mem, 2, 10);
This example uses an 20 element array for the memory. The array is split into 10 blocks of each of which two words in size.
You can allocate a memory block from a memory area using the ctl_memory_area_allocate function. If the memory block cannot be allocated then zero is returned.
unsigned *block = ctl_memory_area_allocate(&m1); if (block) // block has been allocated else // no block has been allocated
When you have finished with a memory block you should return it to the memory area from which it was allocated using ctl_memory_area_free:
ctl_memory_area_free(&m1, block);