Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pointers and memory management

Status
Not open for further replies.

stuartd

Programmer
Jan 8, 2001
146
US
Hi,

Having fallen into the trap of allocating memory, and never freeing it, I have found 'auto_ptr' which handles some of these problems of memory allocation/freeing for me.

Is this a good tool to use, or not? Are there other template classes which do similar things? Can anyone recommend a source where I can read more about this?

Thanks
 

Use
free() in C or
delete in C++ or
at the end of the programme use fflush(stdio).

Amar.
 
Yes, auto_ptr is a very good tool to use. Theoretically, using it, you should never have to use the
Code:
delete
operator (except when you're writing a class). Anything that keeps you from having to remember to write that line of code is a good thing.

There are other "cool" template classes that come with C++, but none are really similar to auto_ptr. If you want to read more about these (which include stuff like function objects and allocators), you can search online for the C++ draft Standard. It's not the real thing, but it's pretty close, and it'll tell you about most of the library facilities that come with standard-compliant compilers.

Another source, and one that's probably more of what you're looking for, is This is a collection of libraries written by people connected with the C++ Standard, and its contents have a good chance of becoming standard in the future. One of the libraries is a smart pointer library, and it contains, among other things, scoped_ptr and shared_ptr. These are auto_ptr's little-known (and unstandard) cousins that could have made it into the Standard, but didn't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top