delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/12/13:45:57

From: "Tony O'Bryan" <aho450s AT nic DOT smsu DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How big can I make my array?
Date: Wed, 10 Jun 1998 19:00:30 +0000
Organization: Southwest Missouri State Universtiy
Lines: 20
Message-ID: <357ED7CD.6B9D2F0F@nic.smsu.edu>
References: <MPG DOT fe223cb1cc75732989717 AT news DOT virgin DOT net> <3578C43D DOT F4DDB90 AT cs DOT com> <MPG DOT fe3efebb95c6032989725 AT news DOT virgin DOT net> <357AB3E4 DOT 316B4ED2 AT cs DOT com> <357c0c3a DOT 24494159 AT news DOT Austria DOT EU DOT net> <357C8BB7 DOT 72AB4B6D AT alcyone DOT com> <357ead02 DOT 3535813 AT news DOT Austria DOT EU DOT net>
NNTP-Posting-Host: jim.a03.smsu.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019