LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How Labview handles array manipulation?

Solved!
Go to solution

I have a large 2by2 array, and I do a lot shifting such as deleting the top row and appending data the lowest row. The size of the array never changes, but I manipulate the data quite a bit.

 

My question is: How does Labview handle this manipulation? Is it smart enough just to manipulate pointers instead of copying values over and over again?

 

I'm looking at the interface with dll, and it seem that Labview for a 2by2 arry just have a pointer to all the number such that the number is just spread accross one block of memory. Is that all Labview does with any size array? Just store in a large chunk?

 

Thank you!

0 Kudos
Message 1 of 9
(4,243 Views)

I'm kind of confused.  You say it is a large 2x2 array.  All 2x2 arrays are the same size, 2 by 2.  So I'm not really sure what you are asking.

 

-Matt Bradley

************ kudos always appreciated, but only when deserved **************************




0 Kudos
Message 2 of 9
(4,232 Views)

MattBradley wrote:

I'm kind of confused.  You say it is a large 2x2 array.  All 2x2 arrays are the same size, 2 by 2.  So I'm not really sure what you are asking.


Hehe, I think he means 2D array.
Cory K
0 Kudos
Message 3 of 9
(4,224 Views)
Solution
Accepted by topic author d1sturbanc3

d1sturbanc3 wrote:

I have a large 2by2 array, and I do a lot shifting such as deleting the top row and appending data the lowest row. The size of the array never changes, but I manipulate the data quite a bit.

 

My question is: How does Labview handle this manipulation? Is it smart enough just to manipulate pointers instead of copying values over and over again?

 

I'm looking at the interface with dll, and it seem that Labview for a 2by2 arry just have a pointer to all the number such that the number is just spread accross one block of memory. Is that all Labview does with any size array? Just store in a large chunk?

 

Thank you!


Yes to the one large chunk, "depends" to the rest of your questions.

 

THe "inplace" memory operators will let you work within a single buffer. Some of the normal array operators will do similarly (replace array sub-set for example). Build array, no.

 

Try using "Tools >>> Profile >>> Show Buffer Allocations...

 

To see where you have additional buffers in your code.

 

BTW: The process of using "Show Buffer..." and then re-writing to eliminate same is sometimes called "Chase the dots".

 

Have fun!

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 9
(4,223 Views)

Just some food for thought:
If your array is always going to be the same size,

and is going to act in a FIFO (first in, first out) manner,

you could use a 'queue'.

 

You can initially set the queue to whatever size you want, since you said it will not change.

Then you can remove elements from the front, and append elements to the end accordingly.

 

Specifically, look at the 'Lossy Enqueue Element' function.

Say you have a queue that has 10 elements:
As you are filling up the empty queue, all elements are added in order.

Once the 11th element is added, the 1st element is removed, and the 11th is added at the end. 

This way, you are guarenteed that the memory allocated is exactly what you are expecting.

Message Edited by Cory K on 05-07-2009 12:42 PM
Cory K
0 Kudos
Message 5 of 9
(4,218 Views)
Yes, LabVIEW stores an array as a single block of memory.  See "storing data in memory" in the LabVIEW help.  LabVIEW will do some optimization - for example, you can get a subset of an array without making a copy so long as you don't modify it.  However, if I've correctly understood that what you are doing is deleting a row, shifting all your array elements up, then adding a new row at the end, there's no way LabVIEW can handle that without copying a lot of data when you shift everything up.  A better approach would be to maintain an index of the "current" end of the array.  Instead of deleting, shifting, and appending, just copy out the current row, replace it with the new data, and increment the current index by 1.
0 Kudos
Message 6 of 9
(4,215 Views)
Yea I tried, but I need to able to get all the items in the queue without flushing it, and Labview doesn't offer that. Plus the queue they offer is not a FIFO queue.  I'm resorting to writng my own Linked list queue in C++ via dll to solve this issue. I'm using delete the first row, and build array right now. I thought about using pointers to indexes, but that's really not that efficent and would be better for me to figure out how to write a C++ dll.
0 Kudos
Message 7 of 9
(4,207 Views)

d1sturbanc3 wrote:
Yea I tried, but I need to able to get all the items in the queue without flushing it, and Labview doesn't offer that. 
 Correct, I do not believe you can index a queue, due to how a queue is structured.

d1sturbanc3 wrote:  
Plus the queue they offer is not a FIFO queue. 
All of the queue functions operate on either the beginning or end of the queue, which would enable the exact functionality of a FIFO queue.
Cory K
0 Kudos
Message 8 of 9
(4,200 Views)

In what way do you feel the LabVIEW queue implementation is not FIFO?

Also, there is a way to retrieve all the elements in a queue - use the Get Queue Status function and set the "return elements?" input to true.

 

Maintaining an index into the array to track the current location is pretty simple and very efficient in terms of memory and speed.

 

EDIT: there's an example here of using an array as a circular buffer, maintaining an index to the current position in the array.

Message Edited by nathand on 05-07-2009 02:00 PM
Message 9 of 9
(4,199 Views)