10-30-2017 11:22 AM - edited 10-30-2017 11:23 AM
Why Enqueue function allocated memory after the first iteration of the loop?
Please see the attached snapshot for the question, question has been taken from CLED sample exam.
Hemant
Solved! Go to Solution.
10-30-2017 11:31 AM
A normal queue grows in memory as more elements are added. Even if you used the fixed size queue, the memory is not allocated until that space is needed. If you need the memory allocated at initialization, then use an RT FIFO or a FOR loop that fills up your queue and then Flush Queue. I was once told that Flush Queue clears out the memory allocated for a queue, then years later told otherwise.
10-30-2017 11:37 AM
@crossrulz wrote:
A normal queue grows in memory as more elements are added. Even if you used the fixed size queue, the memory is not allocated until that space is needed. If you need the memory allocated at initialization, then use an RT FIFO or a FOR loop that fills up your queue and then Flush Queue. I was once told that Flush Queue clears out the memory allocated for a queue, then years later told otherwise.
Can you please explain in little more details about the line that you have mentioned FOR loop that fills up your queue and then Flush Queue to allocate the memory during init.
Hemant
10-30-2017 02:41 PM
@LV_COder wrote:
Can you please explain in little more details about the line that you have mentioned FOR loop that fills up your queue and then Flush Queue to allocate the memory during init.
Use a FOR loop to put N elements into the queue. This allocates all of the memory the queue will need. Then you flush the queue to remove all of the elements in the queue. You now have an empty queue with the memory allocated to handle N elements.
03-28-2019 01:29 AM
normal queue grow in memory when you add more elements, you have to use RT FIFO OR FOR loop that fills queue and then flush out allocated memory.