User`s guide

Creating and Executing Callback Functions
8-17
delete(vid)
clear vid
Monitoring Memory Usage
This example creates a callback function for a timer event that displays the toolbox's
current memory usage and stops the acquisition when the available memory for frame
storage falls below a specified amount.
Creating the Memory Monitor Callback Function
This callback function implements a simple memory usage monitoring function. The
callback function uses the imaqmem function to retrieve two memory usage statistics,
FrameMemoryLimit and FrameMemoryUsed, and then calculates the amount of memory
that is currently left for allocating frames. When the amount of memory available falls
below a specified value, the function outputs a message and stops the object.
function mem_mon(obj,event)
out = imaqmem;
mem_left = out.FrameMemoryLimit - out.FrameMemoryUsed;
msg = 'Memory left for frames';
msg2 = 'Memory load';
low_limit = 2000000;
if(mem_left > low_limit)
sprintf('%s: %d \n%s: %d',msg, mem_left,msg2, out.MemoryLoad)
else
disp('Memory available for frames getting low.');
disp('Stopping acquisition.')
stop(obj);
end
Running the Example
The example acquires frames until the amount of memory left for frame storage reaches
a lower limit specified in the callback function.
1
Create an image acquisition object — This example creates a video input object
for a Matrox image acquisition device. To run this example on your system, use the