Chapter Ten

Win32 Memory Management

Forget everything you ever knew about Win16 memory management. Some of the Win16 memory management functions, such as GlobalAlloc, were carried forward into Win32, but this was done to enable developers to port source code quickly. Underneath, the original functions work very differently, and many new ones have been added.

This chapter starts out with a dose of Win32 memory management theory, which includes coverage of the fundamental heap management functions. Then you'll see how the C++ new and delete operators connect with the underlying heap functions. Finally, you'll learn how to use the memory-mapped file functions, and you'll get some practical tips on managing dynamic memory. In no way is this chapter intended to be a definitive description of Win32 memory management. For that, you'll have to read Jeffrey Richter's Advanced Windows (Microsoft Press, 1997). (Be sure you have the latest edition—a new version may be in the works that covers Microsoft Windows 98/NT 5.0.)

At the time this edition was written, both Windows 98 and Windows NT 5.0 were in beta and not released. Our examination of these betas indicates that the memory management has not changed significantly.