From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carlo Wood To: oliva@dcc.unicamp.br (Alexandre Oliva) Cc: egcs@cygnus.com (egcs@cygnus.com) Subject: Re: malloc/free & new/delete balance Date: Tue, 30 Jun 1998 15:15:00 -0000 Message-id: <199806301523.RAA28699@jolan.ppro> References: X-SW-Source: 1998-06/msg01144.html | Carlo Wood 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