reseting pointer variable - how?

Posted on 2007-07-27
Last Modified: 2010-04-01
I have a pointer IplImage* HSVIMage = 0; //declaration

I process the image in my thread and do some stuff to it. I am now done with it. Later in the thread I want to overwrite the image and reuse it. How do I "reset" the pointer variable for reuse? I tried releasing it ReleaseImage( &HSVIMage) and redeclaring it, but then I get a multiple reinitialization error when compiling. Is it even necessary to "reuse" it?

Question by:Wanderinglazyeye
    LVL 53

    Expert Comment

    Once it's released, it's best to set the pointer to 0, and then it's ready for use again, without having to re-declare it.
    LVL 53

    Accepted Solution

    So, something like :

            IplImage* HSVIMage = 0;
            // create image
            // use image
            // release image
            HSVIMage = 0;

    and now you can create the image again, etc. You don't have to re-use it though - you won't win anything, because you already released the memory that was allocated to the pointer.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
    Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now