Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Most operating systems provide calls to allocate chunks of memory and free them after use. The Z88 is no exception; however, the largest chunk of memory which can be allocated at any one time, and thus the largest chunk which can be guaranteed continuous, is 256 bytes. The only way of ensuring a larger continuous chunk is to set up the application as a so-called 'bad application'. This is wasteful of space and time as the OZ is forced to reshuffle memory, hence the pejorative term attached. A well-written application should only use the small chunks of memory, which for most programs should not be difficult, and indeed should provide a useful discipline as it tends to lead to little wasted memory in comparison with, say, reserving a 100K chunk and probably leaving much of it unused.  

Allocation

Reserved chunks of memory are allocated from larger 'pools'. To reserve memory, the application must first allocate a memory pool, which is done by the call OS_Mop. This allocates a memory pool, set initially to 256 bytes in size, and a handle to refer to it. The only parameter for this call is the memory mask. The value of the mask effects the segment to which the logical address of allocated memory will refer. The allocation routine will find a free page within a bank and place its 14 bit address in register HL. The upper two bits are provided by the upper two bits of the memory mask. The memory mask must be one of MM_S0 to MM_S3 which correspond to segment 0, 1, 2 and 3 respectively.

...

The complement of OS_Mal is OS_Mfr, which will free a chunk of memory. This may be a subset of a previously allocated chunk, although since a partially allocated page cannot be used by other applications, it is only really effective to free whole pages at a time. Finally, the complement to OS_Mop is OS_Mcl. This call will de-allocate all the memory associated with the pool, meaning that each chunk does no have to be separately de-allocated, and close the pool down. Pools must be closed off, even if all the memory has been freed, otherwise the system will loose a handle and some memory.  

Bindings

Now we have seen how memory is allocated we must show how allocated memory can be paged into the logical address space. This involves binding banks to specific segments. Two calls are provided for this purpose: the first, OS_Mgb, return the current binding for a particular segment ie. which bank is associated with the specific segment, but also returns the old binding. The calls are not particularly slow, but if a lot of bank switching is likely to occur then a faster mechanism can be used which makes use of the Z88's 'fast code' facility detailed in "Miscellaneous useful routines".

...

Memory allocation options

OZ offers several settings to select allocation method or several various size of memory. Following pages goes deeper in memory allocation API description.

Child pages (Children Display)
alltrue

...