14 November 2008

A Nifty Trick

When I made EQII support the /LARGEADDRESSAWARE linker flag, I needed a way to see if people had the /3GB boot.ini flag enabled. The reasoning behind this was to detect what the top of our usable address space was and enable some countermeasures if we started using too much of the address space.

Here's how:
LPVOID pHighest = ::VirtualAlloc( 0, 1, MEM_TOP_DOWN|MEM_RESERVE, PAGE_READWRITE );
::VirtualFree( pHighest );


pHighest now contains the highest address the Operating System will let you have. If it's a value over 0x7FFFFFFF then the /3GB flag is enabled (or your software is running on a 64-bit OS). In any case, you now have the power to make decisions about how much address space to use or if you're using too much.

Of course, all of this becomes moot when we start writing software exclusively for 64-bit OSes.

I can't wait.

1 comment:

Anonymous said...

#1 I have to implement the 3bit flag in xp.

#2 I'm waiting for my 64 bit of xp to arrive for vista.

Get out of my HEAD!