T
toton
Hi,
How to find address of a class from inside?
My class having a overloaded new & delete.
new allocates the memory like
void* operator new(std::size_t size) throw(){
cout<<"op new called"<<endl;
void* ptr = std::malloc(size);
if(!ptr){
throw std::bad_alloc();
}
return ptr;
}
delete is like
void operator delete(void* ptr) throw(){
cout<<"op delete called"<<endl;
if(ptr){
std::free(ptr);
}
}
Now is &ptr is the location of the object in memory for new & delete ?
Test* t = new Test(); is how it is initialized. now &t is the memory
location of the class?
These values are not same in the class.... What is the mistake I am
doing here?
The class also has a member variable as pointer to array, like
class Test{
private:
Client* client;
}
after initialization, how to find the location of client from within
the class , &client?
It will be helpful if anyone points out about the addresses. I am
interested in how the class layouts in memory....
thanks
abir
How to find address of a class from inside?
My class having a overloaded new & delete.
new allocates the memory like
void* operator new(std::size_t size) throw(){
cout<<"op new called"<<endl;
void* ptr = std::malloc(size);
if(!ptr){
throw std::bad_alloc();
}
return ptr;
}
delete is like
void operator delete(void* ptr) throw(){
cout<<"op delete called"<<endl;
if(ptr){
std::free(ptr);
}
}
Now is &ptr is the location of the object in memory for new & delete ?
from outside the class?From within class how to get it? &*this ?
Test* t = new Test(); is how it is initialized. now &t is the memory
location of the class?
These values are not same in the class.... What is the mistake I am
doing here?
The class also has a member variable as pointer to array, like
class Test{
private:
Client* client;
}
after initialization, how to find the location of client from within
the class , &client?
It will be helpful if anyone points out about the addresses. I am
interested in how the class layouts in memory....
thanks
abir