Memory Strategies

We can phrase the problem more succintly by asking, how much memory should the compiler set aside fo the variable x of type Window?

Generally speaking we could imagine three different answers to this question.

The first, is what we might call the minimum static space allocation technique. This strategy says that we should only allocate as much memory as is necessary for the base class. This is the technique used by C++.

The second is what we might call the maximum static space allocation technique. Here the idea is to allocate the largest amount of space we might need, that is the size of the memory used by the largest subclass.

The third is what we can call the dynamic space allocation technique. Here we need only allocate for any variable a space large enough to hold a pointer. This pointer will then reference the actual memory value, which will be held somewhere else. This technique is used by languages such as Smalltalk and Java.

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