[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: overloading new/delete
From: Michael Pyne <mpyne () purinchu ! net>
Date: 2007-03-08 22:03:39
Message-ID: 200703081703.43681.mpyne () purinchu ! net
[Download RAW message or body]
On Thursday 08 March 2007 14:03, Christian Ehrlicher wrote:
> Hi,
>
> overloading new/delete seems to be different for msvc than for mingw.
> For mingw I need to use new/delete this way:
>
> void* operator new(size_t size, int myVar);
> void operator delete(void* ptr, size_t size);
>
> but msvc (http://msdn2.microsoft.com/en-us/library/cxdxz3x6.aspx) needs
> this:
>
> void* operator new(size_t size, int myVar);
> void operator delete(void* ptr, int myVar);
>
>
> Is this correct? Any idea how to fix this (for example in
> khtml/rendering/render_object.cpp/.h)?
It looks like the MSVC way is correct. See the C++ FAQ, part 11.14:
http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.14
In the section that talks about solving the fact that memory will leak with
placement new if an exception is thrown, it tells you to define a
corresponding delete operator, with the same signature as the operator new,
except that the size_t is not included. (Think about it, what deallocation
functions ever need the size of the allocated block? ;)
i.e. void* operator new (size_t nbytes, MyType value);
corresponds to void operator delete (void* ptr, MyType value);
So here, if you're correct about mingw's use of operator new and delete then
mingw has a bug. You could possibly use #ifdef'ed macros or something to
work around it but are you sure that mingw has that bug?
Looking at render_object.h, the only operator new which is available to run
is:
void* operator new(size_t sz, RenderArena *renderArena) throw();
There is no corresponding operator delete. But this is only a problem
(according to both MSDN and the C++ FAQ) if the constructor can throw an
exception, and this one is marked as not throwing any. So although defining
an operator delete appropriately would rid us of a compiler warning, I don't
see the next to risk breaking things which seem to be working.
But you're complaining about problems with overloading. What problems are you
having exactly?
Regards,
- Michael Pyne
[Attachment #3 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic