Hello, After reading Queue management section of freeRtos tutorial, i understand that depending on size of data being stored in queue mode of operation can be decided i.e. queue by copy or queue by reference. If the size of data being stored in the queue is large then its preferred to use queue by reference. How do i quantify whether the size of data is large or small ? Is there any guideline/reference for this ? Thank you Regards
There are no hard rules for this so really it has to be your own judgement taking into account the amount of RAM you have available, how long it takes to copy bytes, the number of objects you want to store in the queue at once, and the size of the objects being stored. If you are running out of RAM, or it is taking too long to post, then switch to queuing by reference.
One thing to remember is that Queue ‘By Reference’ isn’t something really uniquely supported directly, but is just a special case of Queue by copy, where what was copied was the pointer to the buffer. One BIG thing to remember is that if you queue a pointer to a buffer, the sender really no longer ‘owns’ that buffer, and should leave it alone until the receiver is done with it. This means that when you decide to use a Queue by reference system, you now need to think about how you are going to manage the lifetime and ownership of the buffers. If the buffers are variable sized, then maybe you need to be allocating them using something like malloc and free (made thread safe or using the FreeRTOS wrappered versions) where the receiver after using the buffer just releases it back to the heap. (And remember to test and handle out of memory conditions and try to avoid fragmenting the heap). If they are all the same sized, perhaps a fixed array of them, and keep a list of which ones are free to be used (I have at times used another queue as a ‘Free List’). Again, you need to be ready to handle no buffers being available (or being able to prove you will always have enough). It is basically a trade off of when the costs of using the simple copying queue that is it worth the cost of managing the buffers to allow a queue by reference approach.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.