Rather a theoretical question — would anyone know how it were possible to make sure a 64-bit process is allocated no more than 2GB of continuous memory.
This came up during the porting of a 32-bit C++ application that does pointer arithmetic (bad!) and relies on subtraction results to fit on a 32-bit integer. Before fixing the pointer arithmetic to correctly handle >2GB ptrdiff_t values, enforcing a 2GB memory space for a process might prove to be be a quick fix.
NOTE: Targeted platforms include Solaris 10, Linux, and Windows.
The C and C++ standards do not require calls to
malloc()oroperator newto return memory that is contiguous with previously-returned memory, and few modern systems would given how virtual memory is doled out in a process.You may be SOL on that front unless you can tell us which platform you’re targetting (there may be a platform-specific solution.)