5.1 The File ‘malloc.c’

This file is found on Sheet 25 of the Source code, and consists of just two procedures:

   malloc (2528)   mfree (2556)

These are concerned with the allocation and subsequent release of two kinds of memory resources, namely:

main memory

in units of 32 words (64 bytes);

disk swap area

in units of 256 words (512 bytes).

For each of these two kinds of resource, a list of available areas is maintained within a resource “map” (either “coremap” or “swapmap”). A pointer to the appropriate resource “map” is always passed to “malloc” and “mfree” so that the routines themselves do not have to know the kind of resource with which they are dealing.

Each of “coremap” and “swapmap” is an array of structures of the type “map” as declared at line 2515. This structure consists of two character pointers i.e. two unsigned integers.

The declarations of “coremap” and “swapmap” are on lines 0203, 0204. Here the “map” structure is completely ignored – a regrettable programming short-cut which is possible because it is not detected by the loader. Thus the actual numbers of list elements in “coremap” and “swapmap” are “CMAPSIZ/2” and “SMAPSIZ/2” respectively.