I create an Area object I need to keep its address.
Both self-reference and self-ptr may be initialized in the initializer list of the ctor. (and it is also easy to do in a method)
class Area
{
private:
Area& selfRef; // size is 8 bytes
Area* selfPtr; // size is 8 bytes - but why bother, just use this
char data[1000]; // size is 1000 bytes
public:
Area() : selfRef(*this), selfPtr(this)
{
for (int i=0; i<1000; ++i) data[i] = 0; // initialize data
};
void foo() {
// easy to do in a method:
Area& localSelfRef = *this; // 8 bytes
// ...
localSelfRef.bar(); // instead of ptr
this->bar(); // direct use of this ptr
selfRef.bar(); // use of class initialized selfRef
}
void bar() {
// ...
}
}
Class size is 1000+ bytes.
selfPtr and SelfRef and localSelfRef are each 8 bytes (on my system).