Windows programmers who require more than 64 KB of data in their programs might be feeling a little nervous at this point. They have a right to be, because the compact and large models are not recommended for Windows programs. This doesn't mean they can't be used, however. The Windows Software Development Kit allows you to install compact-model and large-model Windows libraries, so obviously these models are legal. However, compact-model and large-model programs are subject to a very strict penalty: The data segments must be fixed in memory. They cannot be flagged as moveable.
Why this restriction? There are various reasons; here's an easy example that illustrates one of them. Suppose that somewhere within your program you define a static pointer that looks like this:
char *pointer ;
Because you're compiling for a compact model or large model, this is a far pointer. During your program's execution, you assign a value to that pointer. If the pointer references a moveable data segment, then the value of the pointer must be adjusted when Windows moves the data segment it references. But the compiler and linker will not even generate a relocation address for that pointer because it's not initialized.
Program developers who cry ”but I need the large model“ should consider the alternatives made evident by existing Windows applications. Take a look at some large Windows programs such as Microsoft Excel and Aldus PageMaker. These programs use many code segments but only one data segment. And if these programs don't need the large model, then you probably don't either. If your program needs more than 64 KB of data, you have alternatives to using the compact model or large model. Here they are:
If your program uses large blocks of uninitialized data, do not define these data as variables within the program. Instead, use the Windows GlobalAlloc function (discussed later in this chapter) to allocate a block of moveable memory outside your program.
If your program uses large blocks of initialized read-only data (the most obvious example is ”help“ text), make the data a discardable ”user-defined resource“ (discussed in Chapter 8) to be loaded from the disk only when necessary. This keeps the data out of memory when not needed.
If your program uses large blocks of initialized read-write data, put the initialized data in a discardable ”user-defined resource“ and transfer the data to a global memory block allocated with GlobalAlloc.