<< Back

cesky: , English:

MEMORY

Memory manager

Applications in Litos8 share with system common memory area in the first 64 KB of RAM memory (i.e. all segment registers are set to 0). System core is located in the upper half of 64 KB segment (in version 1.0 system core starts from address 7500h, resident part begins at address 8000h). User application is loaded from address 1000h. Memory area from 0 to about 0600h is reserved for BIOS (including addresses of INT vectors). The area from 0C00h to 1000h is reserved for addresses of jumps to system functions (API). In the remaining space between 0600h and 0C00h lies default stack.

After start, a memory block is allocated to application according to program header. The remaining space is left free until application ask for it. Memory is allocated by system either in multiples of 1 KB pages or (for a block of memory below 1 KB) in powers of two: 8, 16, 32, 64, 128, 256 or 512 bytes.

When allocating small blocks, 1 KB pages are divided into segments of equal size. E.g. application requires 13 bytes of memory. System first determines nearest higher power of two module size, i.e. rounds request to 16 bytes. It looks into table of free 16-byte block and if no such block is free, allocates new 1 KB page, divides it into 64 free 16-byte blocks and assignes one of them to the application.

When releasing the block, system first converts the address of the block address to the number of 1 KB page. From table determines size module of blocks in that page - i.e. 16 bytes. Marks block in table of 16-byte blocks as free and decreases counter of allocated blocks in this 1 KB page. If the counter reaches zero, the 1 KB page will be released.


MemAlloc - allocate memory block

INTPUT:
AX = required size of memory block (0...)

OUTPUT:
AX = address of memory block (NC), or 0 (NULL) on error (CY)
CY = allocation error


MemFree - free memory block

INPUT:
AX = block address (can be NULL)

OUTPUT:
AX = block address, or 0 (NULL) if invalid memory block (CY)
CY = invalid memory block


MemResize - resize memory block

INTPUT:
AX = required new size of memory block (0 = delete block)
BX = address of memory block (NULL = create new block)

OUTPUT:
AX = new address of memory block (NC), or 0 (NULL) on error (CY)
CY = allocation error


MemDup - duplicate memory block

INTPUT:
BX = address of memory block (NULL = create new block)

OUTPUT:
AX = address of new memory block (NC) or 0 (NULL) on error (CY)
CY = allocation error


MemGetSize - get memory block size, check block address validity

INPUT:
AX = block address (can be NULL)

OUTPUT:
AX = block size (NC), or 0 if invalid memory block (CY)
CY = invalid memory block (AX = 0)


MemMaxFree - get maximum available memory block

OUTPUT:
AX = max. size of free memory space


MemGetFreeTotal - get total free memory

OUTPUT:
AX = total free memory (in bytes)


MemGetUsedTotal - get total used memory

OUTPUT:
AX = total used memory (in bytes)


GetSysMemSize - get size of system memory (640 KB)

OUTPUT:
AX = size of system memory (in KB)


Source code MEMORY.ASM

<< Back