LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to initialize a ring buffer of variable size?

Hi there,

 

have a look into the attached vi, pleace. It represents the storage of data into a ring buffer of variable size with subsequent data processing. As we all learned in our first LabVIEW lessons, we should initialize the shift register through the "initialize array" function rather than with an array constant. In the latter case, LabVIEW would have to re-allocate additional memory space to the growing array as soon as the memory space of arbitrary size blocked by the initial constant is exceeded. However, if the vi is stopped before the ring buffer has been completely filled with true data we need to filter out the -inf constants that served as placeholders in the initial array. Otherwise those placeholders would interfere with the subsequent data processing, e. g. the calculation of the mean.

 

So, after this somewhat lengthy preface, my question is: Does anybody know how to reserve a defined memory space for an array without already writing placeholder elements into that memory before the true data arrives?

 

Regards,

Peter 

 

0 Kudos
Message 1 of 5
(4,520 Views)
You have to initialize the array with something. That said, there's a smarter way to do the second part of the operation shown in the VI. Using a Build Array does precisely what you're trying to avoid with the first part: constant memory reshuffling. Attached is an 8.2 version showing a smarter and simpler way to do the same second part of the operation. Note that we don't need to iterate through the array. The previous loop tells us everything we need to know about what to chop off, if anything.
Message Edited by smercurio_fc on 09-11-2008 10:33 AM
Message 2 of 5
(4,508 Views)

Thanks for your useful comment, Smercurio!

 

I thought that LabVIEW will not keep reshuffling memory if I wire the constant N of the For-Next-Loop?

 

Your solution is more elegant anyway, of course.

 

Peter

0 Kudos
Message 3 of 5
(4,476 Views)
Wiring to N will make no difference as to how Build Array works. Build Array has gotten a lot smarter over the versions of LabVIEW. Still, it will eventually always call for extra memory allocation in order to accommodate a larger array.
Message 4 of 5
(4,462 Views)
If you want, I posted an example here which shows efficient dynamic resizing of a circular buffer.

___________________
Try to take over the world!
Message 5 of 5
(4,438 Views)