Chapter9 - 9 Memory management F rankly, it would be nice...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 9 Memory management F rankly, it would be nice to forget about memory. Our programs would just create objects as they please. One after the other, unused objects would vanish into abysses, while those most needed would slowly move closer to the top, like meritorious employees of a large corporation who manage once in a while to catch the attention of a higher officer, and by making themselves indispensable to their immediate superiors will with a bit of luck, at the end of a busy career, be admitted into the inner circle. But it is not so. Memory is not infinite; it does not harmoniously organize itself into a continuous spectrum of storage layers with decreasing access speeds, to which objects would naturally distribute. We do need to fire our useless employees, even if we must call it early retirement imposed with regret because of the overall economic situation. This chapter examines who should be thus downsized, how, and by whom. 9.1 WHAT HAPPENS TO OBJECTS Object-oriented programs create objects. The previous chapter showed how useful it is to rely on dynamic creation to obtain flexible object structures, which automatically adapt to the needs of a systems execution in any particular case. Object creation We have seen the basic operation for allocating space to new objects. In its simplest form it appears as !! x and its effect was defined as threefold: create a new object; attach it to the reference x ; and initialize its fields. A variant of the instruction calls an initialization procedure; and you can also create new objects through routines clone and deep_clone . Since all these forms of allocation internally rely on basic creation instructions, we can restrict our attention to the form !! x without fear of losing generality. We will now study the effect of such instructions on memory management. MEMORY MANAGEMENT 9.1 280 Three modes of object management First it is useful to broaden the scope of the discussion. The form of object management used for object-oriented computation is only one of three commonly found modes: static , stack-based and free . The choice between these modes determines how an entity can become attached to an object. Recall that an entity is a name in the software text representing a run-time value, or a succession of run-time values. Such values are either objects or (possibly void) references to objects. Entities include attributes, formal routine arguments, local entities of routines and Result . The term attached describes associations between entities and objects: at some stage during execution, an entity x is attached to an object O if the value of x is either O (for x of expanded type) or a reference to O (for x of reference type). If x is attached to O, it is sometimes convenient to say also that O is attached to x . But whereas a reference is attached to at most one object, an object may be attached to two or more references; this is the problem of dynamic aliasing, discussed in the previous chapter. this is the problem of dynamic aliasing, discussed in the previous chapter....
View Full Document

This note was uploaded on 10/02/2009 for the course CS 4376 taught by Professor Christeansan during the Spring '09 term at Dallas Colleges.

Page1 / 38

Chapter9 - 9 Memory management F rankly, it would be nice...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online