17.7. Memory Models

The simple DLL above uses no variables at all, either local or global. That makes the DLL simple and easy to understand, but it is not very realistic. A typical DLL needs to use memory. Local variables inside of functions are easy, because they work as expected. However, you have to think a little bit and plan carefully before you use global static or dynamic variables in a DLL, because variables inside of DLLs work in slightly unexpected ways.

Let's say that you want to create a DLL that implements a stack data structure. The stack is to be created dynamically on the heap. This sounds simple, but DLLs allow you to create at least four different memory models for your simple stack DLL, as shown in Figure 17.3.

Figure 17.3. ...

Get Win32 System Services: The Heart of Windows® 98 and Windows® 2000 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.