|
|
| === DEEP DIVE: WINDOWS 9X MEMORY MANAGEMENT, MESSAGE QUEUES, & HARDWARE LIMITS === |
|
While Windows NT (and later XP, 7, and 10) was designed from the ground up as a pure 32-bit, highly secure operating system, Windows 95 and 98 were built on a massive compromise. They had to introduce preemptive 32-bit multitasking while maintaining flawless, native compatibility with 16-bit Windows 3.1 and MS-DOS applications. To program effectively for Windows 9x, you must understand the architectural compromises Microsoft made. This guide explores the memory map, the fragile message queue system, and the hard limits of the OS. 1. Memory Management: The Hybrid 4GB Virtual Address SpaceEvery 32-bit process in Windows 9x is given the illusion of a flat 4GB virtual address space. However, unlike Windows NT where each process is completely isolated, Windows 9x shares massive chunks of this memory map across the entire system. The Win9x Memory MapThe 4GB space is divided into specific regions:
The 64KB Heap Limit (GDI and USER)This is the most notorious limit in Windows 9x programming.
While a 32-bit app can allocate megabytes of standard RAM, the core GUI subsystems ( Consequently, the entire system shares a few localized 64KB heaps for storing window handles, device contexts, brushes, and fonts. If your program leaks just a few kilobytes of GDI brushes every minute, it will exhaust this 64KB heap. When that happens, the legendary “System Resources are dangerously low” warning appears, windows stop drawing properly, and the OS freezes-even if you have 128MB of physical RAM sitting completely empty. 2. Message Queues and The Win16 MutexWindows is event-driven. Keyboard presses, mouse clicks, and window redraw requests are all packaged as “messages” and placed into queues. System Queue vs. Application QueueHardware interrupts (like moving the mouse) are handled by the OS and placed into the System Message Queue. The OS then looks at which window is active and distributes these messages to that specific application’s Thread Message Queue. Your program’s The “Win16 Mutex” (Win16Lock)Windows 9x introduced preemptive multitasking for 32-bit apps, meaning the OS scheduler can pause your app at any microsecond to let another app run. However, the 16-bit core of the OS (USER and GDI) is non-reentrant. It cannot handle being paused in the middle of a task to do another task. To prevent corruption, Microsoft created the Win16 Mutex. Whenever a 32-bit application calls a core GUI function (like
Programming Rule: Keep UI operations fast. Offload file I/O and heavy math to background threads. SendMessage vs. PostMessage
3. Hardware Limits of Windows 9xWhen programming or restoring vintage systems, you must respect the hard limitations of the underlying architecture. Modern assumptions will break the OS. The 512MB RAM Bug (Vcache Limit)Windows 95 and 98 (First Edition and SE) frequently crash or throw “Out of Memory” errors on boot if the system has more than 512MB of physical RAM installed.
Total RAM Limit: 1GB to 2GB MaxEven with the Vcache bug patched, the internal memory manager of Windows 9x physically cannot address more than ~1.5GB to 2GB of RAM. The internal structures track memory in a way that will simply overflow and cause catastrophic Blue Screens of Death (BSODs) if you attempt to boot with 4GB installed. Storage Limits: FAT32 and LBA48
SummaryWriting code for Windows 9x requires surgical precision regarding resource allocation. Always delete your GDI objects, keep your UI threads unblocked to avoid angering the Win16 Mutex, and remember that memory protection in the 1990s was more of a polite suggestion than a strict rule! |