Certification

cancel
Showing results for 
Search instead for 
Did you mean: 

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
(3,645 Views)
Solution
Accepted by topic author LV_COder

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 5
(3,639 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
(3,635 Views)

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


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 5
(3,609 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
(2,765 Views)