Would this work?
// thing.hclass Thing{public: Thing();private: classs Imp; Imp &imp(); char imp_data[1024]; // or whatever};// thing.cppclass Thing::Imp{ // the private stuff};Thing::Thing(){ new(imp_data) Imp(); // placement new?}Thing::Imp &imp(){ return *(static_cast(imp_data));}
Might have placement new syntax wrong there, but would this be an implementation of PIMPL that would mean the actual allocation for the private implementation data would just be part of the normal class memory rather than a pointer to data that could be (potentially) somewhere else leading to cache misses?
I'm really thinking out loud here. Would appreciate anyone's thoughts on this, never seen it done.
You would have to make sure that the size and alignment of imp_data are correct and you are missing a placement delete, but aside from that, yes, this is possible