Search code examples
windowssystem32bit-64bit32-bit

Why can't processes address 4GB of memory in 32-bit systems?


Does anybody know the reason why in a 32-bit Windows systems processes cannot address 4GB of memory but only 2GB ?

Is it only a limitation of Windows systems ?

Note: I am not referring to the total memory that is addressable but the memory which can be addressed by a single process.


Solution

  • why in a 32bit Windows systems processes cannot address 4GB of memory

    But they most certainly can. Your code just doesn't typically have the required access rights to address the upper portion of the address space. User mode code runs at ring 3, to get to the upper part you need ring 0 access rights. Kernel mode.

    Okay, that was a bit tongue-in-cheek, the operating system kernel and drivers that have ring 0 access are not typically thought of being part of the process. Even though they logically are, they are mapped to the same addresses in every process. Technically it would have been possible to map pages dynamically, as the process switches from ring 3 to ring 0 mode, but that would make kernel mode transitions too expensive and cumbersome.

    Intuitively: a file buffer that's filled by ReadFile() could then have an address that overlaps a chunk of operating system code or data. Worst case, it could overlap the file system driver code. Or, more likely, the file system cache. The required page flipping and double-copying would make the reading unpredictably slow. The simplest architectural choice, and the one made in 1992 when nobody was rich enough to afford a gigabyte of RAM, was to simply cut the address space in two so no overlap was ever possible.

    It is otherwise a solved problem, 32-bit versions of Windows are getting rare and a 32-bit process can address 4 gigabytes on the 64-bit version of Windows. It just needs an option bit in the EXE header, the one set by the /LARGEADDRESSAWARE option available in the linker and in editbin.exe