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!

freeing char memory

Status
Not open for further replies.

SteveBrett

Programmer
Apr 24, 2000
107
MT
Hi

if I have the following code:

char szContentLength[50];
memset(szContentLength, 0, 50);

do i need to delete szContentLength to free up the memory or will it be free when it goes out of scope ?

Many thanks

Steve
 
the article seems to relate to C and i'm using c++ ...

would static array alloaction need to be deleted then ? or will it be freed when it goes out of scope - as a general rule i delete memory that is new'd.

thanks

Steve
 
Of course, even though static arrays work the same in C and C++ in this case (there is a difference in that C++ requires a compile-time constant size), C++ has extra tools for the job.

In C++, you would generally use the C++ string class or a vector, deque, or std::tr1::array. ;-)
 
> do i need to delete szContentLength to free up the memory or will it be free when it goes out of scope ?
If you call [tt]new[/tt], then call [tt]delete[/tt] at some point later on, when you're done.

And if you do a [tt]new[size][/tt] then do a [tt]delete[][/tt] and not a [tt]delete[/tt]

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top