Memory handling library

syslib has three options for memory handling. The general routines are useable in all cases, but there are also provisions for user and heap memory, which can drastically reduce memory fragmentations, and are also somewhat faster (especially when releasing groups).

Of course there are also some routines for handling the memory.

Please note that memory management is very import when writing program (the choice of type of memory handling to use can influence the performance of your programs considerably). When a piece of memory has been allocated using one type of allocation routines, is should also be released by the same type, otherwise, your program may crash. Releasing an area of memory more than once can result in crashes. Please note that memory leaks are not as much of a problem in our part of the computing world. All memory owned by a job is always released when that job is removed (except for the SYSTEM job which can never be removed).

General memory handling

Allocation and release
MEMAllocate
Allocate an area of memory. The memory is automatically cleared when allocated.
MEMAllocateFor
Same as MEMAllocate except that the job which should own the memory can now be given explicitly.
MEMRelease
Release an area of memory. Nothing will be done if the address of the area to be released is NULL.
MEMWhenZapped
Define a routine which should be called and/or a byte which should be set when the area of memory is released. This will work both when the job owning that area of memory is released, as when the area is released by a call to MEMRelease.
Inquiry functions
MEMLargest
Determine largest area of free memory in system.
MEMFree
Determine total amount of free memory in system. At the time of writing, this call is actually the same as MEMLargest.
MEMInvalid
TRUE when the pointer is invalid (zero or negative).
Memory handling routines
MEMCopy
Copy some memory from one place to another. This routine is also safe when the areas overlap.
MEMClear
Clear an area of memory (reset to zero).
MEMSame
Compare two areas of memory, equal->TRUE, else FALSE.
MEMDuplicate
Allocate a new area and copy to that area. This call usus MEMAllocate for the new area of memory !

Heap memory

For efficienty, some extra routines are provided for allocating memory in heaps. This prevents memory fragmentation, memory is allocated faster, and all the memory in a heap can be released at once. The memory is not cleared when allocated (for speed).

The MEMHeap library is user code, therefore it is not atomic (and it is not written to be atomic because it is written for maximum speed). If the use makes atomicity necessary, wrap calls in MUTEXCall (cfr. mutex_h) routines. The Heap memory is always owned by the job which called MEMHeapInit. Care should be taken that the Heap memory is no longer available when it was released (possibly because the owner job is removed).

The heap which is referred to by a specific MEMHeap routine is always indicated by an id of type Heap.

MEMHeapInit
Initiate using Heap memory. This allows the definition of the heap block size. This will not allocate any memory.
MEMHeapAllocate
Allocate some Heap memory.
MEMHeapRelease
Release some Heap memory.
MEMHeapZap
Release an entire heap. Counterpart of MEMHeapInit. The heap can no longer be used.
MEMHeapWhenZapped
Define a routine to be called when the heap is released, either by MEMHeapZap or removal of the owning job.

User memory

For efficienty, some extra routines are provided for allocating fixed size memory chunks. To prevent memory fragmentation, this memory will be allocated in blocks (typically 100 chunks at a time). This memory can be allocated and released much faster than normal memory. The memory is not cleared when allocated (for speed).

The MEMUser library is user code, therefore it is not atomic (and it is not written to be atomic because it is written for maximum speed). If the use makes atomicity necessary, wrap calls in MUTEXCall (cfr. mutex_h) routines. The User memory is always owned by the job which called MEMUserInit. Care should be taken that the Heap memory is no longer available when it was released (possibly because the owner job is removed).

The user memory which is used is referred to by a specific MEMUser routine is always indicated by an id of type Chunks.

MEMUserInit
Initiate using user memory. This allows the definition of the chunk size and the blocking factor. This will not allocate any memory.
MEMUserAllocate
Allocate a chunk of user memory. The size is fixed and defined at initialisation.
MEMUserRelease
Release a chunk of user memory.
MEMUserZap
Release all chunks of a given type. Counterpart of MEMUserInit. The Chunks id should no longer be used.
MEMUserWhenZapped
Define a routine to be called when all chunks are released, either by MEMUserZap or removal of the job.

PROGS, Professional & Graphical Software
last edited January 7, 1996