01-08-2014 03:10 AM
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.....
01-08-2014 03:35 AM
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!
01-08-2014 04:08 AM
OK, then arr[0]->elm is points to the first double value in the array
01-08-2014 08:04 AM - edited 01-08-2014 08:06 AM
@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.