03-20-2008 06:42 PM
03-21-2008 01:49 PM
Hi Austin McElroy,
So, you may want to avoid calling the array in memory. It might make more sense to input the array into your first DLL and then pass the output array into the second DLL. That way you're not worrying about the array's location in memory. If you want to check the value of an item in the array before passing the array into the second DLL, use an Index Array VI.
03-21-2008 03:57 PM
03-21-2008 07:26 PM
03-22-2008 10:47 AM
03-22-2008 10:48 AM
03-23-2008 10:05 AM
03-24-2008 07:32 AM - edited 03-24-2008 07:39 AM
And LabVIEW doesn't make copies if it doesn't need too. For this to work however you need to pass the array through the CLN (input it on the left side and output it at the right side of the CLN and from there wire it to the next function), not branch it. That should even work if you configure the array parameter to be a C array data pointer (since LabVIEW will pass the pointer to the actual data to the DLL), but it definitly works without copies for LabVIEW array handles.
@AustinMcElroy wrote:
Ok, so as nk said, even if the idea is terrible why is Labview making extra copies? If I have 2 DLLs in serial to avoid the flag idea, and I am working with datarates of 100MB/s coming off of my acq. card, that is 100MB allocated for the initial array, 100MB allocated for the first DLL and 100MB allocated for the 2nd DLL, per second. Perhaps even more allocations and copying from C back into Labview (I am unsure of this, I will test it tomorrow). This is alot of memory being allocated and copied extraneously. Is there a way to prevent Labview from doing this?
03-24-2008 10:26 AM
Hey Rolf,
Thanks for the indepth response. I tried a very simple example which duplicates what you said to do:
1.) Allocates memory in Labview
2.) Passes this data into a single C DLL
Here is a picture of the block diagram with the memory allocation tool activated (variables obfuscated for your protection). In addition, when the program is run, 2x the memory that I allocated actually gets allocated, which basically confirms what the Labview allocation tool is showing. The data is passed using the Array pointer option in the C node. Even if I wire up the right side of the C node, there are still 2 buffers being allocated.
Thanks,
Austin McElroy
03-24-2008 01:28 PM - edited 03-24-2008 01:31 PM
You haven't proven anything yet. The integer array you pass to the DLL happens to be a constant array and due to constant folding this array is allocated at load time in read only memory and not on the heap. Accordingly LabVIEW has to reallocate a new array to pass to the DLL, since it has to assume that the DLL might be modyfying the memory. Without reallocating a handle the memory pointer would be read only and any attempt by the DLL to modify that memory in any way will cause a general protection error.
@AustinMcElroy wrote:
Hey Rolf,
Thanks for the indepth response. I tried a very simple example which duplicates what you said to do:
1.) Allocates memory in Labview
2.) Passes this data into a single C DLL
Here is a picture of the block diagram with the memory allocation tool activated (variables obfuscated for your protection). In addition, when the program is run, 2x the memory that I allocated actually gets allocated, which basically confirms what the Labview allocation tool is showing. The data is passed using the Array pointer option in the C node. Even if I wire up the right side of the C node, there are still 2 buffers being allocated.
Thanks,
Austin McElroy