Maximum Static Space Allocation

Now let us return to the memory allocation problem, and consider a different solution.

The maximum static space allocation technique would be to determine the largest size block we might ever need, and then allocate that. On the face of it, this does not seem too bad. It is, after all, similar to the way that languages deal with constructs like the union in C, or the variable record in Pascal. It would nicely solve the slicing problem, since we would always have enough room for an value. One unfortunate side effect would be that it would offten allocate space that would then be unused, but we could perhaps live that that problem.

There is one real difficulty, however. In a variant record we know, just by looking at the declaration, how large the largest possibility can be. With a polymorphic variable, it is not until we have seen every class description that we can be certain we have found the largest value. This would mean the maximum amount of space is not known until all classes have been seen.

For this reason, this technique is not used in practice.

[audio] [real] Text to accompany slide11, in Chapter 12 of An Introduction to Object-Oriented Programming