This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: malloc/free & new/delete balance
- To: oliva at dcc dot unicamp dot br (Alexandre Oliva)
- Subject: Re: malloc/free & new/delete balance
- From: Carlo Wood <carlo at runaway dot xs4all dot nl>
- Date: Tue, 30 Jun 1998 17:23:05 +0200 (CEST)
- Cc: egcs at cygnus dot com (egcs at cygnus dot com)
| Carlo Wood <carlo@runaway.xs4all.nl> writes:
|
| > WEAK (void operator delete[] (void *ptr) throw ())
| > {
| > if (ptr)
| > free (ptr);
| > }
|
| > This unbalance between calling `::operator new(size_t)' and `free(void *)'
| > is causing troubles when `operator new(size_t)' and `operator delete(void *)'
| > are overloaded
|
| Agreed, but, for some reason, the FDIS [lib.new.delete.array] defines
| operator new[](size_t) as returning operator new(size_t) by default,
True
| while it states that operator delete[](void*) frees the pointer it is
| given. So, I'd say the implementation is correct, and calling
| operator delete(void*) is non-standard. Too bad. :-(
CD2 reads:
void operator delete[](void* ptr) throw();
void operator delete[](void* ptr, const std::nothrow_t&) throw();
...
Default behavior:
--For a null value of ptr, does nothing.
--Any other value of ptr shall be a value returned earlier by a call
to the default operator new[](std::size_t).33) For such a non-null
value of ptr, reclaims storage allocated by the earlier call to the
default operator new[].
It seems to say that it should undo the allocation that was done by the
call to the default operator new[](size_t) that returned this non-null pointer.
If the default operator new[] calls operator new(size_t), and the
only correct way to undo a call to operator new(size_t) is calling
operator delete(void *), then this means that the default
operator delete[](void*) should call ::operator delete(ptr) imho.
If CD2 is not up to date concerning this, then where can I find the
most up to date document?
--
Carlo Wood <carlo@runaway.xs4all.nl>