Free Lists

A free list is a linked list of nodes which have been allocated but which are not currently in use. Generally such a node already has some sort of pointer which you can use to stitch the list together. If not, you can create one in COBOL by means of a REDEFINES clause or some such trick.

Whenever you need to deallocate a single node, just stick it on the free list. Whenever you need to allocate a single node, check the free list first. If there is a node on it, take it off and use it. Only if the free list is empty do you need to do a real allocation.

If you ever deallocate all the nodes at once, any nodes on the free list become invalid. Be sure you make the free list empty.

A free list can be singly-linked, even if the nodes are designed for use in a doubly-linked list or some other data structure. Just make sure you consistently use the same pointer within the free list.


[chip]Allocating memory [hand]COBOL pointers [trap]Pointer Traps
[home]COBOL Home