On Sun, Oct 31, 2004 at 10:18:54AM -0800, [EMAIL PROTECTED] wrote: > > > 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().
Afaik, when overloading 'placement' new and delete like that, the only time the corresponding overload of delete will be called is if the constructor throws. All other times you have to call the destructor and the right version of delete yourself. > 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. True, but in this case Purify isn't showing anything suspicious. cheers, Graham. -- Graham Bennett --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]