Allocating versus Committing Memory

Under OS/2 Version 2.0, there is a distinction between allocating a memory object and committing that object. This distinction was not present in previous versions of OS/2, and is a very important concept for the application developer to grasp. When a memory object is allocated, space is reserved in the linear address space, but no real storage or swap file space is reserved for the object. This space is only reserved when the memory object or parts thereof are committed. A memory object that has not been committed is known as a sparse object.

A memory object may be committed in two ways:

  • It may be committed (in its entirety) at the time it is allocated, using the PAG_COMMIT flag in the DosAllocMem() function.

  • It may be committed in stages at some later point, using the DosSetMem() function.

    The former technique is intended for small memory objects, the size of which is fixed and can be determined in advance by the application developer. The latter technique is intended for memory objects such as external data files, which may vary in size.

    Memory must be committed prior to being accessed by the application. Failure to do this will result in a page fault (Trap 000E) exception.


    [Back: DosAllocMem() Function]
    [Next: Committing Storage at Allocation]