Reputation: 10063
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.
Upvotes: 1
Views: 201
Reputation: 941317
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
Upvotes: 2
Reputation: 16582
The simplistic answer is that some of the virtual address space is reserved for the OS to map stuff into, such as its own memory space, the VM page table, hardware devices, etc.
It could, in theory make more available (and indeed you can tell Windows to let you have ~3GB, though it's not enabled by default in case some software/drivers/etc has a problem with it), but you won't get the full 4GB without crippling the OS's ability to run the system efficiently.
Even if you do expand the user-land space to 3GB on windows, applications will not by default get the extra range. Windows requires applications to have a flag set (build with /LARGEADDRESSAWARE under MSVC, don't know about other build environments) or they are restricted to 2GB, to avoid any issues caused by software making assumptions about addresses.
Upvotes: 2
Reputation: 165212
32-bit Windows systems split the 4GB virtual memory range equally between the user and the system, such that each only has 2GB of (virtual) usable space.
See: http://msdn.microsoft.com/en-us/library/windows/desktop/aa366912%28v=vs.85%29.aspx
Upvotes: 0