Abstract
In the diagram package the user can create a diagram made up of a series of shapes, each of which contains a number of items. Each shape can consist of any number of items, and there can be any number of shapes. Thus, when the program is written, it is not known how many items are required, or how many shapes are needed. This can be determined only when the program is being run. However, space is needed in which these items and shapes are stored. It would be possible to predeclare this using VAR statements of the form:
where ShapeMax and ItemMax are suitable constants, and GCommand is a record defining an item (see chapter 9). This is limiting, as the user is restricted as to the number of GCommands that can make up a shape, and the number of shapes. It is also wasteful of memory, as some shapes may require very few GCommands. A much better solution is one where the memory for a new GCommand is acquired as and when it is needed, that is, when the program is run. This is achieved using the heap (see Wirth[1]).
Preview
Unable to display preview. Download preview PDF.
References
Nikiaus Wirth Algorithms and Data Structures Prentice-Hall 1986
Niklaus Wirth Programming in Modula-2 Fourth Edition 1988 Springer-Verlag
Author information
Authors and Affiliations
Copyright information
© 1991 R. J. Mitchell
About this chapter
Cite this chapter
Mitchell, R.J. (1991). The Heap and One-way Linked Lists. In: Modula-2 Applied. Macmillan Computer Science Series. Palgrave, London. https://doi.org/10.1007/978-1-349-12439-8_12
Download citation
DOI: https://doi.org/10.1007/978-1-349-12439-8_12
Publisher Name: Palgrave, London
Print ISBN: 978-0-333-55453-1
Online ISBN: 978-1-349-12439-8
eBook Packages: EngineeringEngineering (R0)