LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any function like malloc and free in labview?

Im writing a vi that will handle my memory request.

Im doing a very high speed video record sessions , and the frames cant be saves on hardisk in realtime), so im saving the frames on memory, and i want to use memory as

much as i can(~2GB) and to save the maximum frames that i can save (and it depends on bit depth, height, width, total memory).

 

 

VI Operations={

Allocate Memory (frame width, frame height,TotalMemorySize) ,

Add Frame(index) ,

Get Frame (index),

Free Memory

In each record session, there will be a different FrameWidth and Height, so the maximum frame that i can save in memory may be different and equal to

IndexMax=TotalMemorySize/(FrameWidth*FrameHeight)

Im doing this by allocating a 3D array [FrameIndex , row , column]

The fact that the width and height change in different sessions indicate  that i need an ability to free the previous allocated 3D array memory and allocate a new one.

(lets say that i have 2GB total memory..)

 

0 Kudos
Message 1 of 6
(4,015 Views)

This request really takes the system and the programmer to the limits....

First of all:

LabVIEW does not have any functions like malloc and free. LV wants to prevent the user to have to think about stuff like this. On the other hand, the memory management in LV is therefore hard to do or even impossible, at least to such an extend as you request.

 

Some thoughts about your application:

1. If you want to have about 2GB of framedata in RAM during runtime, you will need the large memory awareness active. Otherwise, a 32 bit OS will give you "out of memory" messages. Refer to the LV help "VI memory usage".

2. Storing the data in an array could be a difficult task. Arrays have to be in memory without any gap. Therefore, you'd encounter "out of memory" messages even if your RAM totals enough free memory (theoretical).

3. The idea of linked-lists does not compy in LV since you cannot store pointers to structs (since those are abstracted from the user).

4. Maybe you should take a look into vision

 

hope this helps,

Norbert 

 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 2 of 6
(4,007 Views)

...adding to Norbet's post...

 

Another way to get LV to allocate space for your images is to use a queue where each entry is an image. This breaks up the memory into resonable pieces and only a buffer large enough for the image needs allocated, side-stepping the contigous memory req.

 

Just write a full set of "dummy" image when you start (to tell LV allocate the sapec now) then dequeue all of the elements so that the buffers are marked as free.

 

Managing memory in LV is a lot like surfing. The slightest gesture implies your intent. Both of which can take time to understand and master.

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 3 of 6
(3,995 Views)

Hey, thank for replies

 

Ben, your solution seems to work, (the queue is actually a linked list, and that exactly what i was looking for).

But there is some bug, after the session is over, im dequeing the elements and save them to one big file, frame by frame, and sometimes i get an out of memory error in the middle of dequeing.

i will continue to investigate this...but in general your solution is working

Thanks.

0 Kudos
Message 4 of 6
(3,950 Views)

You might be accumulating file writes faster than the system is actually writing the data to disk.  Try using "Flush File.vi" to force the issue.

 

-Jim

Message 5 of 6
(3,921 Views)
I hate to say this but this is one application where it is better to use C than LV.  Or maybe a combination of both.  Write a C DLL to do memory stuff and use LV to write the top level code.  Call the DLL functions from LV when necessary.
- tbob

Inventor of the WORM Global
0 Kudos
Message 6 of 6
(3,911 Views)