Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   IMAQ images and Memory Management (http://www.chiefdelphi.com/forums/showthread.php?t=101027)

malachias 24-01-2012 11:35

IMAQ images and Memory Management
 
I have not seen any code that disposed of Image instances (i.e., GetImaqImage()). I do, however, see code delete the source image and then use the underlying Image instance, which leads me to believe that ImageBase is not the owner of the Image instance. Am I to assume that they are managed by the IMAQ vision library. I can see generating a lot of these Images during a competition and although they tend to be small I can easily run out of memory if the resource is not freed.

Thanks

basicxman 24-01-2012 11:42

Re: IMAQ images and Memory Management
 
Destructor of ImageBase:

Code:

ImageBase::~ImageBase()
{
        if(m_imaqImage)
                imaqDispose(m_imaqImage);
}

Snippet from header:

Code:

protected:
        Image *m_imaqImage;


Tommy.Brown 26-01-2012 00:00

Re: IMAQ images and Memory Management
 
If you are working with pointers, you should just be able to delete the images out of memory each time through the loop once you are done processing them.

Image *genericImage = NULL;
//Code to get value and store it in genericImage
delete genericImage;

basicxman 26-01-2012 00:04

Re: IMAQ images and Memory Management
 
Quote:

Originally Posted by Tommy.Brown (Post 1113703)
If you are working with pointers, you should just be able to delete the images out of memory each time through the loop once you are done processing them.

Image *genericImage = NULL;
//Code to get value and store it in genericImage
delete genericImage;

For Image objects you should use imaqDispose.

Tommy.Brown 26-01-2012 00:25

Re: IMAQ images and Memory Management
 
Ah, I have yet to look into the inner workings of the 7000 lines of nivision.h... I just went off of my prior C++ experience. Sorry for the misinformation.

wireties 26-01-2012 08:31

Re: IMAQ images and Memory Management
 
There are versions of GetImage that take a pointer to an Image so you can allocate your own image data structure (once using new HSLImage() then set the size) and use it over and over again. This will be a bit faster. When programming in a real-time environment it is better to NOT be doing memory allocations or formatted output in loops where you hope to have deterministic (execute in the same amount of time each time through) performance.

HTH


All times are GMT -5. The time now is 17:40.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi