This is the mail archive of the gcc-bugs@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: Error in g++ library, function ___builtin_vec_new


Alexandre Oliva wrote:
> 
> On Jan 28, 2000, f981500@FFZJ0LX0.bank.dresdner.net (James Kanze) wrote:
> 
> > I've encountered an error in the default implementation of
> > ___builtin_vec_delete in the C++ library.  From disassembly, it appears
> > that this function calls free to free the memory
> > rather than operator delete, as is required by the standard.
> 
> I can't find this requirement in the standard.  The specification of
> new[] and new[]nothrow do specify that they return their non-array new
> counterparts, but the specification of delete[] and delete[]nothrow
> just say they reclaim the memory allocated by the corresponding new[],
> no mention to the non-array delete.

This is a useability & quality of implementation issue.
I recall this discussion from a while back. Maybe it was here or maybe
on clc++. I'd forgotten about it, because I thought it'd been fixed.

You're correct in saying that the standard does not say "operator delete[]
must call operator delete". But consider what function is guaranteed to
reclaim the memory allocated by operator new? The user is allowed to
provide an alternate implementation of operator new (and a matching
operator delete), therefore calling operator new cannot make assumptions
about the internal implementation. All we know is we're getting memory
from somewhere and the guaranteed way of giving it back is with
operator delete.

I think it would be better for,
Either operator new[] use malloc and operator delete[] use free.
Or operator new[] use operator new and operator delete[] use operator delete.

The latter has the advantage in useability that, should the user replace
operator new and operator delete, all allocations are captured. Should this
additional function call turn out to be a performance hit, the user is free
to replace operator new[] and operator delete[] with versions which directly
call malloc and free.

nathan

-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
Never hand someone a gun unless you are sure where they will point it
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk

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