03-09-2009 09:04 AM
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..)
03-09-2009 09:24 AM
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
03-09-2009 09:43 AM
...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
03-10-2009 08:35 AM
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.
03-11-2009 11:18 AM
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
03-11-2009 11:32 AM