LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

List of pointers Moveblock

Solved!
Go to solution

Hello,

I have a list of memory adresses and use Moveblock to get  the values (which is a 640 x 480 2D arrray in my case). This just runs nicely as long as call Moveblock multiple times (e.g. using different memory adresses) to get all my 2D arrays (120 arrays). The problem is that it takes a few tens of ms fro Labview to generate this 120 X 640 X 480 (when using a loop that calls 120 times Moveblock). Is there a way to call directly a list of pointers and retrieve directly the corresponding 3D array.
Best

0 Kudos
Message 1 of 16
(5,198 Views)

Can you share your LabVIEW code? You can't provide a list of pointers to MoveBlock, but perhaps you're doing something in your LabVIEW code that could be improved.

0 Kudos
Message 2 of 16
(5,123 Views)

OK. Here is what I try to do.
CODE:

 

#include <stdio.h>
#include <stdint.h>
/* LabVIEW created typdef */
typedef struct {
int dimSizes[3];
uint8_t val[1];
} images;
typedef images **imagesHdl;


_declspec(dllexport) void main(int *x, imagesHdl array);
_declspec(dllexport) void main(int *x, imagesHdl array)
{
// get size from input array
int i, j, k;
/* dimSizes[0] is the number of pages */
int numpag = (*array)->dimSizes[0];
/* dimSizes[1] is the number of rows */
int numrow = (*array)->dimSizes[1];
/* dimSizes[2] is the number of columns */
int numcol = (*array)->dimSizes[2];
int ps = numrow * numcol;

// derefence pointers
//????
}

 

So I have a list of memory adressess that actually point to "number of pages" images (of size width x height). I would like to fill the array "images" with all those individual images.

Best

0 Kudos
Message 3 of 16
(5,000 Views)

I don't understand what you're trying to do at all. I asked if you could share your LabVIEW code, and you posted some incomplete C code instead that doesn't show anything about what you're trying to accomplish, and doesn't match your description. There's no 'list of memory adressess that actually point to "number of pages" images' in the C code. Instead, there's a structure that contains dimensions and a pointer to a single block of memory that contains all the array elements.

 

LabVIEW stores arrays in contiguous memory regardless of the number of dimensions, so you only need one address to refer to the entire array. Does that help in trying to fill it all at once?

0 Kudos
Message 4 of 16
(4,983 Views)

Well my Labview code is nothing else than a loop (where the number of iterations (n) is just the number of memory adresses) with Moveblock inside. This works nicely (I can build a 3d array having n images) but it is slow. That is why I wanted to this with a DLL. 

0 Kudos
Message 5 of 16
(4,963 Views)
Solution
Accepted by topic author WG67

Well and where does your array of pointers come from? The C code simply gets a 3D array from LabVIEW, which is not an array of pointers but simple a memory array with [colomn * rows * pages] elements. This is the array that you get after you copied your array of pointers, which is nowhere to be seen in this C code, with MoveBlock() into a LabVIEW 3D array. In order to do the same that you do in LabVIEW with MoveBlock() you would have to have two parameters, the first being the array of pointers (plus its 3 dimensions, C pointers don't have inherent size information attached) and the second being the LabVIEW 3D array and then you would first have to use LabVIEW memory manager functions to resize that 3D array handle appropriately before you can start to copy the data into it by using memcpy() or MoveBlock() would work too and is only slightly slowever than the best memcpy() implementations.

 

Most likely you won't be able to squezze out a lot of performance even if you implement that in C. Copying memory takes time, if you do it by calling a C function like MoveBlock() from LabVIEW or a function like memcpy() in a C code.There is a good chance that you can gain a little since LabVIEW diagram code does some sanity check too, that you can omit in your C code, but it likely won't be like some exponential improvement. LabVIEW is implemented in C(++) and does generally optimizations where a C programmer would have to spend quite a bit of time to get to the same level. Obviously your specific case of calling external code like MoveBlock() does limit the possibility for LabVIEW to do much optimization, as it doesn't know what the called code behind the Call Library Node does (even if you call a LabVIEW manager function here) so it can't do things like loop unrolling, code rescheduling and many more things without risking that some, unknown to LabVIEW, side effect of the called function would be influenced.

 

You think your LabVIEW code is nothing more than a loop, but you call in there the MoveBlock function and the way you do that could be the important detail that we miss now in order to understand what could be improved. Since it is such a simple VI I also do not understand the reluctance to simply post it, but make instead some pseudo code that you want us to finish for you to do the same that you have done in the LabVIEW code, which we can't see.

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 16
(4,961 Views)

I am abroad and do not have Labview on my Laptop. 

My question was just on "how to derefence pointers" not "how to get the memory adresses". 

I just have noticed that indexing (making a 3d array from a 2 array) is very slow with Labview. And I believe calling "Move Block"  in Labview 120 times is not that fast.

0 Kudos
Message 7 of 16
(4,956 Views)

@WG67 wrote:

I am abroad and do not have Labview on my Laptop. 

My question was just on "how to derefence pointers" not "how to get the memory adresses". 

I just have noticed that indexing (making a 3d array from a 2 array) is very slow with Labview. And I believe calling "Move Block"  in Labview 120 times is not that fast.


Dereferencing pointers is in fact not fundamentally different than getting the memory address. And since this is pretty advanced C programming, discussing it theoretically is always much much more inefficient than showing the actual code.

 

A very quick guess from your mentioning that making a 3D array from several 2D arrays is very slow (which is the opposite of indexing an array) would be that you have used the Build Array inside the loop. That is indeed very inefficient! Much more efficient would be to simply use the autoindexing feature of the loop and let it build the 3D array from the 2D arrays.

 

And if Build Array is indeed the problem you are seeing, having attached your VI for sure would have prompted Nathan in his first post to point that out to you already and the thread could have been closed.

 

And an even more performant solution, albeit somewhat hairy since you start to do really pointer arithmetic in LabVIEW itself, would be to preallocate the 3D array properly, then inside the loop just provide the MoveBlock() function the correct offset into this 3D array data, when copying the data from your array of pointers into the LabVIEW 3D array. This is exactly what you would normally do in C.

 

Using Build Array in a loop is equivalent to using realloc() in each loop iteration to resize the array to be able to accomodate one more element. 

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 16
(4,951 Views)

Well I use auto-indexing 😉

0 Kudos
Message 9 of 16
(4,941 Views)

@WG67 wrote:

Well I use auto-indexing 😉


You'll have to show your code! Before even considering to think about C programming, which is non-trivial, error prone, and time intense to debug I really want to see what you have done so far.

Rolf Kalbermatter
My Blog
0 Kudos
Message 10 of 16
(4,934 Views)