On Aug 9, 4:44 pm, MJ_India <mail.mohitj...@gmail.com> wrote:
2) If I add extra parameters to new and delete [for ex: void
*operator new(size_t count, bool dummy), void delete(void
*where, bool dummy)] and redefine new to new(true) in required
modules.
a) Operator new (and new[]) works fine, but I don't know how
to make the delete work.
b) I don't know if it is standard and would be supported by
all C++ compilers.
It's standard. Theoretically, the steps you may have to take to
replace new and delete may vary; in practice, it's sufficient to
link you versions in before the library.
Replacing global new and delete, or just adding new placement
new and delete (as you're doing) can be tricky. The main
problem is that a delete expression always calls the
non-placement version, do you need to provide the non-placement
version of operator delete. And since this has to work with the
non-placement operator new as well, you have to replace that was
well. And you have to memorize which allocator or memory pool
was used, in order to know which one to use in the delete; the
classical solution for this is to use some sort of hidden
memory for this, e.g.:
union BlockHeader
{
Allocator* allocator ;
MaxAlignType dummyForAlignment ;
} ;
void*
operator new( size_t n )
{
BlockHeader* p = static_cast< BlockHeader* >(
malloc( n + sizeo=
Thank you for the reply. I hope this will be useful.