LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

pre-allocation of queue memory for queue of arrays

Hey folks,

I'm working on optimizing a timing critical VI.  This VI is the
producer in a producer consumer architecture.  I'm trying to populate
a queue from file in a manner that is as efficient as possible.  My
current plan of attack is:

- read block of data from file and populate array (pre-allocated).
- add array (always of the same size) to Queue with a max size defined
(e.g. 50 elements)
- This is in a while loop as is the standard producer consumer model.

To improve the performance I would like to ensure that there is no
dynamic memory allocation on the Queue's behalf.  This is easily done,
from what I understand, if the data type in the queue is of the same
type (e.g. double, int).  However, since the size of an array can vary
does this mean that any queue of arrays will always dynamically
allocate memory?  Is there a way to ensure that the queue will always
use the same memory as in a circular queue?

Thanks,

Steve
0 Kudos
Message 1 of 2
(3,370 Views)

Setting a max size for the queue does not preallocate memory. The only thing it does is to prevent the Enqueue primitive from enqueuing if the queue is full.

However, the queue primitives themselves are optimized to reuse memory - whatever you push into them remains in place and is then reused. I assume that this means that if you are enqueuing in a loop, the loop wire will create a copy each time, but I suppose it's also possible the queue will create a copy.

If you want to manage this more efficiently, I suggest you create an array and rotate it. I'm not sure if there is an efficient way to rotate a 2D array other than going over it line by line, but the new inplace memory structure might help you.

Alternatively, you don't have to rotate the array and you can just maintain an index of where you currently are and how many elements are in the queue. That way, you can preallocate the 2D array and just go over it line by line.


___________________
Try to take over the world!
Message 2 of 2
(3,357 Views)