Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: shout on October 06, 2005, 09:46 PM

Title: Having a pointer freed when the calling function exits
Post by: shout on October 06, 2005, 09:46 PM
How would I go about creating a function that spits out a pointer to an allocated chunk of memory, then when the calling function exits, free the pointer? I was thinking something like what _alloca() does.
Title: Re: Having a pointer freed when the calling function exits
Post by: MyndFyre on October 06, 2005, 10:38 PM
Use a managed language?  :P
Title: Re: Having a pointer freed when the calling function exits
Post by: shout on October 06, 2005, 11:06 PM
Quote from: MyndFyre on October 06, 2005, 10:38 PM
Use a managed language? :P

How helpful.
Title: Re: Having a pointer freed when the calling function exits
Post by: K on October 06, 2005, 11:25 PM
well, are you using C or C++? if you're using C++, I would recommend using something like std::auto_ptr (http://www.roguewave.com/support/docs/sourcepro/stdlibref/auto-ptr.html) or for more flexibility, boost::shared_ptr (http://www.boost.org/libs/smart_ptr/shared_ptr.htm) / boost::shared_array (http://www.boost.org/libs/smart_ptr/shared_array.htm)
Title: Re: Having a pointer freed when the calling function exits
Post by: rabbit on October 07, 2005, 12:25 PM
Is boost paying you or something?
Title: Re: Having a pointer freed when the calling function exits
Post by: K on October 07, 2005, 01:26 PM
Quote from: rabbit on October 07, 2005, 12:25 PM
Is boost paying you or something?

Is there a problem with recommending a free library that accomplishes the result he is looking for?
Do you have anything helpful to add to the discussion or are you just looking to get banned again?
Title: Re: Having a pointer freed when the calling function exits
Post by: rabbit on October 09, 2005, 02:57 PM
Ech..I was just wondering.  You bring it up a lot.  And I'd prefer not to be banned T.T