LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Why is array size limited between LV and dll when both are set large enough?

I have a dll being called in vi, and I need to pass in (and get out) 3 arrays of 100000 elements. However, there appears to be a 64k limitation on the sizes even though both LV and the dll are configured for 100k. Any ideas?
0 Kudos
Message 1 of 9
(3,451 Views)
> there appears to be a 64k limitation on the sizes even though both LV and the dll are configured for 100k

Do you have a U16 (unsigned 16 bit integer) controlling the index?

Les Hammer
0 Kudos
Message 2 of 9
(3,451 Views)

Sorry for rising this topic from the dead, but I'm stuck in a dll created in matlab and been called in LabVIEW. I'm not being able to pass and fetch an array with 8192 elements, altough it worked with 8191 elements. I then switched the array to single (I'm creating the dll, so I can change it) and managed to get to my desired 12.000 elements. What could be causing this limitation? Since it worked with another type of variable, in shoudn't be caused by an wrong index variable type as pointed by LesHammer.

0 Kudos
Message 3 of 9
(2,963 Views)

Does your DLL by chance do something with the array that creates a 2D array with both sides set to the initial array length?

8192 x 8192 x 8 bytes per double = 512 megs, which is the maximum size limit of a single object in 32 bit Matlab.

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

No, it doesn't. In fact, I did a pretty simple test. Created an input array with 8191 elements and threw right into the output and it worked. Did the same thing with a 8192 array and bam. LV crashes. And of course, I test everything in matlab before (the code, not the dll) and it work as intended.

 

Another strange thing: more often than not the resulting array in labview returns full of garbage, like numbers ranging from -10e37 to 10e37... Oh, well, I think I'm cursed.

0 Kudos
Message 5 of 9
(2,949 Views)

I think I've found the source of my problem. I'm using the matlab code generator to create the dll. Probably the array pointer is not a long int and its overflowing. This explains why I can work with larger datasets when the variable type for the array is changed to single.

 

My problem now is to find out how to tell to matlab that I want a long int as array pointer. Does anyone knows how to do it?

 

Thanks in advance.

0 Kudos
Message 6 of 9
(2,923 Views)

Do you use unbounded arrays when creating the Matlab DLL? That would result in mxArray.. datatypes as parameter and interfacing to them without some LabVIEW to Matlab conversion wrapper is definitely not something I would recommend.

The mxArray stuff is Matlabs version of managed memory objects, while LabVIEW has handles and .Net uses .Net objects for doing managed objects.

All three are managed environments in terms of managing memory allocation and lifetime of data objects, but each is different and has its own methods to manage them.

If you set the Matlab Code generator to use bounded arrays instead the generated code should use standard C array pointers instead and you can much easier interface directly to them, at the cost of these arrays not being dynamically resizable anymore but you really do not want to pass managed datatypes between different managed environments, unless you are prepared to write some wrapper code in C to properly translate between the different managed paradigmas.

Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 9
(2,911 Views)

I solved my problem with an option inside the matlab compiler screen. The field name is "Generate ->more settings->Dynamic memory allocation threshold" inside Matlab coder and it was set to those 64kB.I've set it to a higher number and everything works well, now.

 

About rlofk suggestion, I do not have enough dll knowledge to understand what has been said. Lol.

Message 8 of 9
(2,884 Views)

@Giovanno wrote:

 

About rlofk suggestion, I do not have enough dll knowledge to understand what has been said. Lol.


Somewhere in the Matlab Builder settings you have an option to use bounded or unbounded arrays. Unbounded arrays are passed to the DLL as mxArray.. structures that contain not only the array itself but also flags that indicate how the array can be resized/deallocated if necessary and other such management stuff. You will need to call Matlab library functions to do so.

 

Bounded arrays are passed as simple C datapointer and can not be resized dynamically. It's most likely what you are using and Matlab probably uses the setting you found to allocate and process arrays with this maximum bound.
 

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 9
(2,881 Views)