Something like this in C++:
template<class T>
class CompressedPointer {
public:
T &operator*() const {
return *static_cast<T *>((uint64_t)ptr << 3);
}
/* It's not safe to construct a CompressedPointer<T> from an arbitrary T*;
you probably want to malloc and construct via the CompressedPointer itself */
template<Args...>
static CompressedPointer malloc(Args...) {
/* allocate 8-byte aligned sizeof(T) in first 32GB, then construct T in it */
}
private:
uint32_t ptr;
}
[Edit] Extra crazy idea: Take an existing large C++ codebase. For each struct T in the codebase, use static analysis to determine if T is ever stack-allocated (or otherwise incompatible with CompressedPointer). If not, automatically rewrite all "T*" to "CompressedPointer<T>" and all "new T(...)" with "CompressedPointer<T>::malloc(...)". I suspect this would work for 90% of the heap allocations in a typical C++ codebase...