Hi Graham,

> > All classes that derive from XMemory use "placement" new with a 
> > MemoryManager instance, and the normal delete expression.  The call 
stack 
> > you posted looks fine. 
> 
> But is this the correct behaviour?  I think the destructor for the
> object should be called, then the operator delete from the MemoryManager
> interface called explicitly.

It's the correct behavior.  XMemory has a class-specific operator new and 
operator delete.  Operator new allocates memory for the object, plus 
enough memory to store a pointer the supplied MemoryManager instance, 
which it places at the beginning of the block.  It then returns a pointer 
into the block after the pointer to the MemoryManager.  The delete 
expression runs the destructor for the object, then calls the 
class-specific operator delete, which retrieves the pointer, then calls 
the MemoryManager's deallocate() function.

For more details, take a look at the implementations of XMemory::new() and 
XMemory::delete().

Often, when I see a crash in freeing memory, I discover that the crash is 
a symptom of a previous bad transaction with the heap, like deleting a 
pointer that's already been deleted.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to