LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to find out how much memory is left while a VI is running?

Solved!
Go to solution

I have a VI that acts as the user interface to another program.  The other program collects gigabytes of data and stores it in memory as it cannot save it fast enough.  Currently, I run task manager (Windows 10) and watch as the computers memory gets consumed so I know when to stop the underlying program.  Is there any way from within the LabVIEW VI to find out how much memory is left?  From what I've read, it appears there once was and there's a lot of chatter but I cannot find an example that shows how to do it or where the icon may be on the function pallet.

0 Kudos
Message 1 of 12
(2,723 Views)

Hi Jim,

 

I don't know where and how you are looking for information, but I found this one by using Google with "labview find available memory"…

 


@Jim12345678 wrote:

I have a VI that acts as the user interface to another program.  The other program collects gigabytes of data and stores it in memory as it cannot save it fast enough.


When you have two separate programs (aka executables) you need to use PerformanceMonitor calls to gain access to other process' statistics from your "UI program"…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 12
(2,715 Views)

Hello,

 

I came across that in my search, but it's not generating the same values as performance monitor (it's generating a wildly unrealistic value) nor does the reported value change while performance monitor shows the free memory dropping.  I believe the value reported by the Window's 10 task manager.  I'm surprised that LabVIEW (2018) doesn't provide a simple way to do this.

 

Thanks

0 Kudos
Message 3 of 12
(2,662 Views)

If you only need the available memory with regards to the Windows OS, you might have some luck with the following function call: GlobalMemoryStatusEx function 

Of course, if you're running Win 64-bit and LabVIEW 32-bit (I'd guess pretty common), there's a good chance that the value you receive is irrelevant...

 

The commands described in the question here (Get-Process with total memory usage) might be useful if you wanted to find the memory used by LabVIEW (and compare that to some static value, e.g. 3GB or similar).

 

For both of these approaches, you'll probably have to use system calls, either via the Call Library Function Node or the System Exec node (respectively).


GCentral
0 Kudos
Message 4 of 12
(2,649 Views)

@Jim12345678 wrote:

I have a VI that acts as the user interface to another program.  The other program collects gigabytes of data and stores it in memory as it cannot save it fast enough.  Currently, I run task manager (Windows 10) and watch as the computers memory gets consumed so I know when to stop the underlying program.  Is there any way from within the LabVIEW VI to find out how much memory is left?


You don't really give sufficient information. The memory used is just a number and may or may not be useful to you anyway. How are the gigabytes of data" acquired and "stored in memory"? Is this in ever-growing arrays (1D, 2D)? Some complicated dynamic data? Waveforms? Higher structures? Do you have data duplication (local variables, indicators, etc.).

 

Arrays require to be contiguous in memory, so the amount of contiguous memory is much more important than the amount of free memory and if you constantly grow structures, the entire data needs to be moved to a new contiguous memory area once the current allocation runs out. Expensive and wasteful and you'll quickly fragment you memory.

 

So, the correct way would be to allocate an array at a fixed maximum size when the program starts (e.g. with NaN or some other sentinel value), then replace with real data as it arrives, keeping track of the insert point. If the initial allocation succeeds, you are guaranteed to never run out of memory and it is easy to track how much of that allocation has been filled by just comparing the insert point to the total size.

 

I really have no idea about your expertise, but I have the feeling that you are searching for a solution in the wrong place. It probably can be solved by significantly tightening the code.

Message 5 of 12
(2,642 Views)

@altenbach wrote:

So, the correct way would be to allocate an array at a fixed maximum size when the program starts (e.g. with NaN or some other sentinel value), then replace with real data as it arrives, keeping track of the insert point. If the initial allocation succeeds, you are guaranteed to never run out of memory and it is easy to track how much of that allocation has been filled by just comparing the insert point to the total size.

 


Another vote for this, a similar method worked great for me when I needed to have a crapload of memory used at once.

 

Not to mention it'll be faster than dynamically creating the arrays, which might be what you're doing now.

0 Kudos
Message 6 of 12
(2,638 Views)

Thanks for the suggestions. I'm aware of all of those things.  I'm just looking for a decent measure of how much memory is left so I know to stop the code before the computer starts to hang up.

0 Kudos
Message 7 of 12
(2,623 Views)

@Jim12345678 wrote:

Thanks for the suggestions. I'm aware of all of those things.  I'm just looking for a decent measure of how much memory is left so I know to stop the code before the computer starts to hang up.


As I said, it can hang up way before you run out of free memory, so any such measure is probably not helpful. It will not tell you how much of the free memory is contiguous. 

0 Kudos
Message 8 of 12
(2,608 Views)
Solution
Accepted by topic author Jim12345678

Here is the answer you are looking for, but probably not the answer you need.

 

Frozen_0-1585347583219.png

 

Frozen_1-1585347614630.png

 

---------------------------------------------
Certified LabVIEW Developer (CLD)
There are two ways to tell somebody thanks: Kudos and Marked Solutions
Message 9 of 12
(2,597 Views)

This appears to work, but it brings the system to halt with every call.

 

Thanks

0 Kudos
Message 10 of 12
(2,530 Views)