One of the principal features of Windows is that it lets the user run more than one application at a time. Since multiple applications place greater demands on memory than does a single application, Windows' ability to run more than one application at a time has a significant impact on how you write applications. Although many computers have at least 640K of memory, this memory rapidly becomes limited as the user loads and runs more applications. In Windows, you must be conscious of how your application uses memory and be prepared to minimize the amount of memory your application occupies at any given time.
To help you manage your application's use of memory, Windows uses the same memory-management system for your application's code and data segments that you use within your application to allocate and manage global memory blocks. When the user starts your application, Windows allocates space for the code and data segments in global memory, then copies the segments from the executable file into memory. These segments can be fixed, movable, and even discardable. You specify their attributes in the application's module-definition file.
You can reduce the impact your application has on memory by using movable code and data segments. Using movable segments lets Windows take advantage of free memory as it becomes available.
Summary: Windows automatically reloads discarded code segments as needed.
You can minimize your application's impact on memory by using discardable code segments. If you make a code segment discardable, Windows discards it, if necessary, to satisfy requests for global memory. Unlike ordinary memory blocks that you may allocate, discarded code segments are monitored by Windows, which automatically reloads them if your application attempts to execute code within these segments. This means that your application's code segments are in memory only when they are needed.
Discarding a segment destroys its contents. Windows does not save the current contents of a discarded segment. Instead it assumes that the segment is no different than when originally loaded and will load the segment directly from the executable file when it is needed.