Mail Archives: djgpp/1998/06/12/13:45:57
Gerhard Gruber wrote:
> Aha? I thought that new usually uses malloc?
I would be surprised if the C++ standard requires malloc to be the backend for
new. Most likely not, though. Not even as a convenience for the compiler
writers.
In either event, it's not relevant since new and malloc are totally
incompatible systems of memory allocation. new knows about constructors (among
other things), and malloc doesn't. By the same token, delete knows about
destructors and free doesn't. The two systems track memory in totally
different ways, and one will not properly clean up memory created by the other.
There are many other reasons, too, but I just wanted to cover the basics. You
can, though, use malloc/free and new/delete in the same program as long as you
use them consistently. People who say to never use malloc in C++ programs are
just purists who think malloc should be eliminated.
- Raw text -