LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Access LV array data in C

Hello, 

I tried to work with LV 2D double array data in C (dll) via Call Library Node. In the C code, the LV array is a member of a rather complicated cluster array. I have the finall pointer to the required double LV array and I would like to copy the data using memcpy or MoveBlock. (I know the double data size in bytes)

I read the source http://zone.ni.com/reference/en-XX/help/371361J-01/lvconcepts/how_labview_stores_data_in_memory/

where it is written, that the array contains the size specification at the beginning of the allocated memory. More precisely, 4 bytes for each dimension. In my case of 2D array, the size specification memory block is 8 bytes followed by the double data.

 

My question is whether the pointer to the array points to the double data or to the beginning of the memory with the size specification.....

0 Kudos
Message 1 of 4
(2,501 Views)

If you have created the C source template from the Call Library Node file the answer should be easy.

 

You end up with something like:

 

struct {

       int32 dim1;

       int32 dim2;

       double elm[1];

} My2DArrayRec, **My2DArrayHdl;

 

struct {

       ........

       My2DArrayHdl arr;

       ........

} MyComplexStruct;

 

Looking at this code the answer should be easy.

 

arr is a pointer to a pointer to the first dimension size!

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 4
(2,494 Views)

OK, then arr[0]->elm is points to the first double value in the array 

0 Kudos
Message 3 of 4
(2,479 Views)

@charlie87 wrote:

OK, then arr[0]->elm is points to the first double value in the array 


Yes, sort of but that is rather ambigues and most C compilers won't accept that unless you set the warning level to a very low level. arr is not an array pointer but an array handle. So the array index syntax arr[x] never really exists and is strictly speaking invalid. Some C compiler may still allow arr[0] to mean the same as (*arr) but that is very ugly.

 

I prefer a more descriptive syntax similar to (*arr)->elm.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 4
(2,461 Views)