Allocation and Management

OS/2 Version 2.0 allows a memory object to have any size between 1 byte and 512MB, which is the maximum amount of memory addressable in a process address space. A program uses the DosAllocMem() and DosAllocSharedMem() function calls to allocate memory objects. The use of these and other available functions to manipulate memory objects is described in OS/2 Version 2.0 - Volume 4: Application Development.

Allocating a memory object with a size of 1 byte will in reality reserve a full 4KB page, since the operating system allocates memory on a page-by-page basis. In order to avoid large amounts of wasted memory, an application, which uses many small memory objects, should request the allocation of a storage pool from the operating system, and then suballocate this storage as required. This technique reduces memory fragmentation and allows more efficient use of memory resources. It is described in detail in OS/2 Version 2.0 - Volume 4: Application Development.

When a memory object is allocated, its base address and maximum size are defined. The location of the object and the size of the object is fixed for the lifetime of the object. It can be neither re-sized or moved within the virtual address space. By default, however, no physical storage is reserved for a memory object at allocation time; the operating system merely reserves a range of addresses in the process address space for that object. A memory object which is allocated in this way is known as a sparse object.

Before an application can write to a memory object, the object must be committed; upon commitment, physical storage is reserved for the memory object. Storage can be committed at either of two points:

  • The memory object may be committed in its entirety at the time the object is allocated. This method is typically used for small memory objects, the size of which is fixed and predetermined prior to execution.

  • The memory object or any part of it may be committed after allocation, in 4KB (page) units. This method is typically used for memory objects such as documents or spreadsheets, which are likely to increase in size during execution.

    This effectively allows an application to increase the size of a memory object in a series of steps, as the storage requirements for that object increase during application execution. A memory object can therefore be allocated at its maximum possible size during initialization, without imposing large memory overheads on the system as a whole, since real storage is reserved only as it is required.

    Each page within the memory object can be individually committed, or a group of pages may be committed at the same time, up to the maximum size of the memory object stipulated during allocation. Note that this is one of the few instances where an application developer must be aware of the paged memory architecture.


    [Back: Memory Objects]
    [Next: Guard Page Technique]