Int 21H [3.0] Function 58H (88) Get or set allocation strategy

Obtains or changes the code indicating the current MS-DOS strategy for allocating memory blocks.

Call with:

If getting strategy code

AH = 58H

AL = 00H

If setting strategy code

AH = 58H

AL = 01H

BX = desired strategy code

00H = first fit

01H = best fit

02H = last fit

Returns:

If function successful

Carry flag = clear

and, if called with AL = 00H

AX = current strategy code

If function unsuccessful

Carry flag = set

AX = error code

Notes:

The memory allocation strategies are:

First fit: MS-DOS searches the available memory blocks from low addresses to high addresses, assigning the first one large enough to satisfy the block allocation request.

Best fit: MS-DOS searches all available memory blocks and assigns the smallest available block that will satisfy the request, regardless of its position.

Last fit: MS-DOS searches the available memory blocks from high addresses to low addresses, assigning the highest one large enough to satisfy the block allocation request.

The default MS-DOS memory allocation strategy is First Fit (code 0).

Example:

Save the code indicating the current memory allocation strategy in the variable strat, then change the system's memory allocation strategy to "best fit."

strat dw 0 ; previous strategy code

.

.

.

; get current strategy

mov ah,58h ; function number

mov al,0 ; 0 = get strategy

int 21h ; transfer to MS-DOS

jc error ; jump if function failed

mov strat,ax ; save strategy code

; now set new strategy

mov ah,58h ; function number

mov al,1 ; 1 = set strategy

mov bx,1 ; 1 = best fit

int 21h ; transfer to MS-DOS

jc error ; jump if function failed

.

.

.