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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

memory allocation/deallocation

Status
Not open for further replies.

michaelkrauklis

Programmer
Dec 5, 2001
226
US
I'm a little confused as to the memory management of MFC. eg:

//Say you make a pointer declaration as so
char *temp_str = "temp string";

//Then you wrap a CString around it
CString *temp_cstring = new CString( temp_str );

//Then what happens when you deallocate the CString?
delete temp_cstring;

Does it deallocate the memory for temp_str as well as temp_cstring or only the memory allocated to the CString? MYenigmaSELF
myenigmaself@yahoo.com
 
This is from the MSDN library under CString:

"the constructors copy the input data into new allocated storage"

which means that when you do this:
new CString( temp_str );

the constructor makes a copy of the string. You will have to destroy the original "char*" string yourself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top