This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: malloc/free & new/delete balance
- To: egcs at cygnus dot com
- Subject: Re: malloc/free & new/delete balance
- From: Nathan Myers <ncm at cygnus dot com>
- Date: Sun, 05 Jul 1998 17:12:20 -0700
- Newsgroups: cygnus.egcs
- Organization: http://www.cantrip.org/
- References: <199807031202.IAA26419.cygnus.egcs@maniac.deathstar.org>
Sol Foster wrote:
>
> Alexandre Oliva <oliva@dcc.unicamp.br> wrote:
> > I didn't write delete[] calls free(), I just said it frees
> > (deallocates) the memory. No where it says delete[] calls delete by
> > default, and, since it does for new[] and new, I took it as a
> > difference, rather than as an omission.
>
> I'd argue it's strongly implied that, if the memory is allocated with new,
> then it is deallocated with delete. It's disappointing that the standard
> doesn't specify this, but then, it doesn't even specify that the memory is
> actually given back to the heap.
*You* try to write a requirement that the storage is re-used without
actually specifying an algorithm. The C committee gave up, and the
C++ committee doesn't claim to be (much :) smarter.
> Is the extra function call that much more expensive than what free does
> internally?
In a *good* implementation you can expect the whole new/delete cycle
to take fewer than 40 instructions, on average. Hence, an extra
function call might be considered expensive. (Now, *good* implementations
are not as common as I would like, but that ought to be fixable.)
Nathan