[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: memory debugging and C++ (program keeps crashing)



On Sunday 29 September 2002 14:38, Shyamal Prasad wrote:
>     "Marc" == Marc Singer <elf@buici.com> writes:
>
>     Marc> Actually, with GCC it doesn't matter which call you use.
>     Marc> New uses the malloc function.  You can free () or delete
>     Marc> memory allocated with malloc () or new.  New and delete are
>     Marc> 'syntactic sugar' for malloc and free.
>
> You mean that very loosely, right? new and delete call constructors
> and destructors respectively. This is particularly important when you
> do stuff like delete [].
>
> /Shyamal

indeed.  Using free() on a piece of memory allocated by new is rather 
dangerous, you have no idea what the C++ library is doing behind the scenes.  
Plus as Shyamal points out, none of the destructors that should be called 
would be.  Just because malloc() happens to be the deep, deep implementation 
does not mean there is not useful and important code inbetween.



Reply to: