This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: malloc/free & new/delete balance


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]