DOS Fn 48H: Allocate Memory / Query Free Memory
Expects: AH 48H
BX requested amount of memory in paragraphs (16-byte chunks)
Returns: AX error code if CF is set to CY
segment address of allocated block (if no error)
BX size of available RAM, in paragraphs (if allocation fails)
Info: Allocates a block of memory BX paragraphs long, returning the
segment address of that block in AX (block starts at AX:0000).
If the allocation fails, the Carry Flag is set, an error code is
returned in AX, and BX contains the maximum size allowable (in
paragraphs) for an allocation.
To determine the largest block available, it is a common practice
to set BX=ffffH before the call. The allocation will fail,
returning the available allocation size in BX.
To allocate from upper▲ memory, the upper memory link must be
active and the memory allocation strategy must be set to one of
the options which allocate high memory. For instance:
■ Use fns 5800H and 5802H to obtain the current allocation
settings. Save them.
■ Use fn 5803H (set UMB link) with BX=0001H
■ Use fn 5801H (set strategy) with BX=40H-42H or 80H-82H.
■ Use fn 48H (alloc mem) to allocate the memory. If NC, and
AX >= A000H, then the high allocation worked. Otherwise, you
just got some conventional memory.
■ Use fns 5801H and 5803H to restore the saved allocation
settings before terminating.
See Accessing Upper Memory for related info.
Notes: ■ When a process receives control via Fn 4bH EXEC, the largest
available memory block has been allocated to it already.
It is usually necessary to shrink the allocation that starts at
your PSP (via fn 4aH) in order to make conventional memory
available for allocation.
■ When a program is loaded high via loadhigh, its code will be in
upper memory, but additional allocations will be made according
to the current allocation strategy (see fn 5801H).
See Also: Memory Control Functions
Memory Control Block