overloading new operator
-
Hi Can anyone tell me why it is necessary to overload new and delete operator Thanks in advance
ragavan wrote:
Can anyone tell me why it is necessary to overload new and delete operator
It is certainly not necessary to overload these operators. It can be done, sure, but it is never needed. I never did that myself (and I don't see a reason why I would do so). An example of what you can do by overloading these operators is what MFC does: it allows to track memory leaks.
Cédric Moonen Software developer
Charting control [v1.2] -
ragavan wrote:
Can anyone tell me why it is necessary to overload new and delete operator
It is certainly not necessary to overload these operators. It can be done, sure, but it is never needed. I never did that myself (and I don't see a reason why I would do so). An example of what you can do by overloading these operators is what MFC does: it allows to track memory leaks.
Cédric Moonen Software developer
Charting control [v1.2]Well put. It seems like the OP meant to say "when it is necessary" rather than "why it is necessary".
-
Hi Can anyone tell me why it is necessary to overload new and delete operator Thanks in advance
ragavan wrote:
why it is necessary to overload new and delete operator
to put some extra
printf()
inside them for instance !? ;)
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
Hi Can anyone tell me why it is necessary to overload new and delete operator Thanks in advance
One (the only?) reason is when the objects need to be allocated in a non-standard way. For example, for performance reasons, you may be using per-thread heaps so as to avoid heap contention in a multi-threaded application (if the application is allocation intensive). Or if you have to allocate lots of smaller-sized objects (< 16-32 bytes) and you need to optimize the allocations by allocating larger blocks and then chunking them yourself. Combining the Win32 heap's and C-RTL's overhead, a heap allocation can have between 20-32 bytes of overhead. So if you need to allocate one million objects of 8 bytes each, this overhead (both space and execution time) can start to add up quickly. Granted, the average everyday developer does not need to be (or simply is not) concerned with such things, but those are some reasons I have done it in the past. Peace!
-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
ragavan wrote:
Can anyone tell me why it is necessary to overload new and delete operator
It is certainly not necessary to overload these operators. It can be done, sure, but it is never needed. I never did that myself (and I don't see a reason why I would do so). An example of what you can do by overloading these operators is what MFC does: it allows to track memory leaks.
Cédric Moonen Software developer
Charting control [v1.2]Cedric Moonen wrote:
It is certainly not necessary to overload these operators. It can be done, sure, but it is never needed. I never did that myself (and I don't see a reason why I would do so).
Yikes! Please be careful saying things like this to less-experienced developers - just because you never had a reason to do so does not mean that one does not exist. :P
Cedric Moonen wrote:
An example of what you can do by overloading these operators is what MFC does: it allows to track memory leaks.
Unless MFC changed recently, I believe this was mostly done by the use of
DEBUG_NEW
instead ofnew
, and this in turn happened thanks to a#define
that was in effect for debug builds. That is not really overloadingnew
... Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
Cedric Moonen wrote:
It is certainly not necessary to overload these operators. It can be done, sure, but it is never needed. I never did that myself (and I don't see a reason why I would do so).
Yikes! Please be careful saying things like this to less-experienced developers - just because you never had a reason to do so does not mean that one does not exist. :P
Cedric Moonen wrote:
An example of what you can do by overloading these operators is what MFC does: it allows to track memory leaks.
Unless MFC changed recently, I believe this was mostly done by the use of
DEBUG_NEW
instead ofnew
, and this in turn happened thanks to a#define
that was in effect for debug builds. That is not really overloadingnew
... Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFilesJames R. Twine wrote:
Yikes! Please be careful saying things like this to less-experienced developers - just because you never had a reason to do so does not mean that one does not exist.
That was certainly not my intention. Maybe I expressed myself badly.
Cédric Moonen Software developer
Charting control [v1.2]