Certification

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Why Enqueue function allocate memory after the first iteration of the loop?

Solved!
Go to solution

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

0 Kudos
Message 1 of 5
(1,060 Views)
Solution
Accepted by topic author Hemant_LV
10-31-2017 10:10 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.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 2 of 5
(1,054 Views)

@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

0 Kudos
Message 3 of 5
(1,050 Views)

@Hemant_LV 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.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 4 of 5
(1,024 Views)

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.

0 Kudos
Message 5 of 5
(180 Views)