mike.m.schmidt@gmail.com wrote:
Quote:
[..]
I need to know exactly what happens when the delete operator runs on a
dynamically allocated object. I've read that the memory is pushed
onto the free list and adjacent free blocks are coalesced into one
larger block. On the other hand, when an object on the stack is
destroyed, the stack pointer is simply adjusted. Therefore, objects
on the stack should take less time to clean up, but that is not
reflected in my timing values. I'd like to know why.
|
There is a function called 'deallocation function', which the what the
global operator delete is usually called, I think. The statement with
the 'delete' operator for a single object (not an array) has two steps,
it calls the object's destructor and then calls the deallocation
function. It's a bit simplified, for more read the Standard, [expr.delete].
What the deallocation function does under the covers is
implementation-defined. Whether "the memory is pushed", or "adjacent
blocks are coalesced" is not defined by the language itself. Perhaps
you need to see the documentation for your compiler/library to get a
better idea of what's really going on behind the covers. Of course, you
can also redefine the operators 'new' and 'delete' for your class and
the overloaded 'delete' is going to be called instead of the
'deallocation function' (or, rather, it will be the deallocation
function in that case).
You seem to be saying that you see no difference if the object is
dynamic or automatic. Perhaps your timing mechanism needs to have
higher resolution?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask