Re: when delete do not call destructor
S S <sarvesh.singh@gmail.com> wrote:
I can not write full code as it is 20000 lines kind of copywrite
thing. But I am writing below required details,
class A{
public:
void *operator new(size_t, void *p) {return(p);}
void *operator new(size_t n) throw(std::bad_alloc)
{ My_allocation_routine(&someInternalVar, n);}
void operator delete(void* p, size_t n) {My_deallocation_routine(p,
n);}
..
..
~A() {}
};
I did,
A* obj = new A;
delete obj;
I set breakpoint in destructor of this class, it does not reach there.
Don't know why?
I tried the following:
#include <iostream>
using namespace std;
void* My_allocation_routine(int* i, size_t n)
{
cout << "My_allocation_routine\n";
return malloc(n);
}
void My_deallocation_routine(void* p, size_t n)
{
cout << "My_deallocation_routine\n";
if (p)
free(p);
}
class A
{
static int someInternalVar;
public:
void *operator new(size_t, void *p)
{
return(p);
}
void *operator new(size_t n) throw(std::bad_alloc)
{
return My_allocation_routine(&someInternalVar, n);
}
void operator delete(void* p, size_t n)
{
My_deallocation_routine(p,n);
}
~A()
{
cout << "in d_tor\n";
}
};
int A::someInternalVar = 0;
int main()
{
A* obj = new A;
delete obj;
}
The output was as follows:
My_allocation_routine
in d_tor
My_deallocation_routine