LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory Management in LabView / DLL

Hi all,

I have a problem concerning the memory management of LabView. If my data is bigger than 1 GB, LabView crashes with an error message "Out of Memory" (As LabView passes Data only by value and not by reference, 1 GB can be easily achieved). My idee is to divide the data structure into smaller structures and stream them from Hard Disk as they are needed. To do so, i have to get access to a DLL which reads this data from disk. As a hard disk is very slow in comparison to RAM, the LabView program gets very slow.
Another approach was to allocate memory in the DLL and pass the pointer back to LabView...like creating a Ramdisk and reading the data from this disk. But memory is allocated in the context of Labview...so LabView crashes because the memory was corrupted by C++. Allocating memory with LabView-h-Files included doesnt help because memory is still allocated in the LabView context. So does anybody know if it's possible to allocate memory in a C++-DLL outside the LabView context, so that i can read my Data with a DLL by passing the pointer to this DLL by LabView? It should work the following way:
-Start LabView program--> allocate an amount of memory for the data, get pointer back to labview
-Work with the program and the data. If some data is needed, a DLL reads from the memory space the pointer is pointing at
-Stop LabView program-->Memory is freed

Remember: The data structure should be used like a global variable in a DLL or like a ramdisk!

Hope you can understand my problem

Thanks in advance

Christian

THINK G!! 😉
------------------------------------------------------------------------------------------------
Using LabView 2010 and 2011 on Mac and Win
Programming in Microsoft Visual C++ (Win), XCode (Mac)
0 Kudos
Message 1 of 6
(5,047 Views)
If you're crashing when trying to allocate 1GB of memory I don't think it's going to matter where you try to create this chunk of memory. Remember that you're trying to allocate a contiguous chunk of memory. That's why you're getting the "Out of memory" error. I think your fundamental problem is that your machine doesn't have enough RAM, or it's being chopped up by too many running processes.
0 Kudos
Message 2 of 6
(5,023 Views)
yeah, that's right...but i don't try to allocate a chunk of 1gb of ram...it about 200mb, but there are some sub-vis processing this data, so as the calls are only done by value, it gets to this 1gb. Normally, the program shouldn't crash with an out-of-memory-error because windows should generate a swap-file to handle this. I think this crash is an error caused by labview and NOT because theres not enough RAM. My question is if theres a possibilitie to allocate an amount of space outside the labview-heap and pass the pointer between sub-vis. then i can access the same memory-space in every subvi.

Christian

THINK G!! 😉
------------------------------------------------------------------------------------------------
Using LabView 2010 and 2011 on Mac and Win
Programming in Microsoft Visual C++ (Win), XCode (Mac)
0 Kudos
Message 3 of 6
(5,017 Views)
If you have multiple subvis grabbing 200MB each you might try using the "Request Deallocation" function so that once a vi is done processing it releases the memory.

LabVIEW Help: "When a top-level VI calls a subVI, LabVIEW allocates a data space of memory in which that subVI runs. When the subVI finishes running, LabVIEW usually does not deallocate the data space until the top-level VI finishes running or until the entire application stops, which can result in out-of-memory conditions and degradation of performance. Use this function to deallocate the data space immediately after the VI completes execution."

Programming >> Application Control >> Memory Control >> Request Deallocation

I think it first appeared in LabVIEW 7.1.


Message Edited by Troy K on 07-14-2008 09:36 AM
Troy - CLD "If a hammer is the only tool you have, everything starts to look like a nail." ~ Maslow/Kaplan - Law of the instrument
Message 4 of 6
(5,008 Views)
Yeah, thats true...i use this function. But the deallocation isn't done as it only deallocates unused memory...dont ask me why, but it doesn't work...

THINK G!! 😉
------------------------------------------------------------------------------------------------
Using LabView 2010 and 2011 on Mac and Win
Programming in Microsoft Visual C++ (Win), XCode (Mac)
0 Kudos
Message 5 of 6
(4,975 Views)
Please check out the tutorial Managing Large Data Sets in LabVIEW.  It gives two native LabVIEW solutions to your problem (no DLL needed).  I would recommend the single-element queue method, since it closely approximates a pointer and has faster performance for large data.  However, I have used both solutions over the last eight years and they both work nicely.  If you run into any problems, please let us know.

If you have LabVIEW 8.5 and above, you may also wish to use the InPlace element to avoid memory copies.

For the record, if nothing else is running, LabVIEW itself fragments memory and puts a cap on the largest array you can allocate.  In LabVIEW 7.1 and previous, that cap is about 1.1GBytes.  For LabVIEW 8.0 and later, the cap is about 800MBytes (more features, more things in memory).  More information is in the above tutorial.
0 Kudos
Message 6 of 6
(4,957 Views)