Right now, xQueueGenericCreate calls pvPortMalloc to allocate a Queue_t, then calls it again to allocate the storage space for the queue data. If you have a lot of semaphores, this means a lot of calls to pvPortMalloc all asking for one-byte heap blocks, which will waste quite a bit of space on heap metadata! It would be more efficient (both in RAM space and time) to pack the Queue_t and its data area into a single heap allocation, of size (sizeof(Queue_t)+uxQueueLength*uxItemSize+1), and have the data area live immediately after the Queue_t in RAM (even for actual data queues, this shouldn’t hurt things). This cannot cause any alignment problems because the queue data area is only ever touched by memcpy, which has no alignment requirements.
Originally discussed at https://sourceforge.net/p/freertos/discussion/382005/thread/68357f7e/.
Log in to post a comment.