Flylib.com

Books Software

 
 
 

Memory as a Programming Concept in C and C++ - page 7

Review

A program written in C/C++ is stored in one or more source modules as plain ASCII text files. These are compiled into object modules. Because we are focused on all memory- related aspects of this process, we emphasize the fact that all symbolic references from the source program are replaced by address references in the object module; the address references are in the form of logical (or relative) addresses, which represent the location of an object as the offset (distance) from the beginning of the load module (or an activation frame for a local object). During relocation and linking, all object modules are "forged" together into a single load module. During that process, all logical addresses are updated vis-  -vis the beginning of the new load module being created. This load module contains all information about what the abstract program address space should look like.

When we request the operating system to execute a program, its load module is loaded into memory - that is, the program address space is created and mapped to physical addresses. Now the program can be executed one instruction at a time, in the usual way. Thus, on a certain level of abstraction, we can pretend that the C/C++ instructions of the source program are mapped onto sets of machine instructions stored in the memory and that data ( variables , objects, etc.) of the program are mapped to appropriate segments of the memory. (Static data - i.e., global objects and local objects defined with the storage class "static" - are mapped into the static data region of the program's memory, while dynamic data are mapped into the dynamic data region of the program's memory.) This level of abstraction is useful for discussions of programs and their semantics. Each object in a program thus corresponds to a well-defined segment of memory, and the program's instructions merely modify these objects; that is, the instructions either read the data from or store new data in these memory segments.

Exercises

2.1 In a C/C++ program, can you define a global variable that is not accessible by a certain function?

2.2 Can a global variable in a C/C++ program be located in the static data section of the object module of the program? Can it be located in the dynamic section of the load module?

2.3 What is the difference between logical address and physical address?

2.4 What is the difference between object module and load module?

2.5 What does "address space" refer to?

2.6 What is the system stack for?

2.7 Why does the load module have no dynamic data section even though the address space does?

2.8 The statements of a C/C++ program are translated by the compiler to machine instructions. Where are these instructions stored?

2.9 Is there any difference between linking and relocation? If so, describe it.

References

Some very good contemporary textbooks on principles of operating systems:

Crowley, Ch., Operating Systems, A Design-Oriented Approach , Irwin/McGraw-Hill, New York, 1997 .

Silberschatz, A., Galvin, P. B., and Gagne, G., Operating System Concepts , Wiley, New York, 2002 .

Stallings, W., Operating Systems - Internals and Design Principles , Prentice-Hall, Englewood Cliffs, NJ, 2001 .

Tanenbaum, A. S., Modern Operating Systems , Prentice-Hall, Englewood Cliffs, NJ, 2001 .

An excellent text (recommended in several chapters of this book) that is focused on C++ and includes topics on effective memory management:

Sutter, H., Exceptional C++ , Addison-Wesley, Reading, MA, 2000 .

Fundamentals of compilers principles and techniques; an oldie, but still the best text around:

Aho, A. V., Sethi, R., and Ullman, J. D., Compilers - Principles, Techniques, and Tools , Addison-Wesley, Reading, MA, 1988 .

Other texts on the fundamentals of compiler principles and techniques:

Pittman, T., and Peters, J., The Art of Compiler Design, Theory and Practice , Prentice-Hall, Englewood Cliffs, NJ, 1992 .

Waite, W. M., and Carter, L. R., An Introduction to Compiler Construction , HarperCollins, New York, 1993 .

Fundamentals of computer architecture:

Hamacher, C., Vranesic, Z., and Zaky, S., Computer Organization , McGraw-Hill, New York, 2002 .

Hennessy, J., and Patterson, D., Computer Architecture: A Quantitative Approach , Elsevier, New York, 2002 .

{% if main.adsdop %}{% include 'adsenceinline.tpl' %}{% endif %}

Murdocca, M., and Heuring, V. P., Principles of Computer Architecture , Prentice-Hall, Englewood Cliffs, NJ, 1999 .

Stallings, William, Computer Organization and Architecture - Principles of Structure and Function , Prentice-Hall, Englewood Cliffs, NJ, 1996 .

Fundamentals of programming languages:

Clark, R. G., Comparative Programming Languages , Addison-Wesley, Reading, MA, 2001 .

Mitchell, J. C., Concepts in Programming Languages , Cambridge University Press, 2002 .

Pratt, T. W., and Zelkowitz, M. V., Programming Languages - Design and Implementation , Prentice-Hall, Englewood Cliffs, NJ, 2001 .

The Internet is an excellent source for technical details about memory and memory management in various operating systems, but there is no guarantee of how the links will be maintained in the future:

Gorman, M., "Code Commentary on the Linux Virtual Memory Manager", http://www.csn.ul.ie/~mel/projects/vm/guide/pdf/code.pdf .

Gorman, M., "Understanding the Linux Virtual Memory Manager", http://www.csn.ul.ie/~mel/projects/vm/guide/pdf/understand.pdf .

Myers, N. C., "Memory Management in C++", C++ Report , July/August 1993 (part 1) and December 1993 (part 2); also at http://www.cantrip.org/wave12.html .

Russinovich, M., "Inside Memory Management", part 1, Windows & .NET Magazine , http://www.winntmag.com/Articles/Index.cfm?IssueID=56&ArticleID=3686 .

Russinovich, M., "Inside Memory Management", part 2, Windows & .NET Magazine , http://www.winntmag.com/Articles/Index.cfm?IssueID=58&ArticleID=3774 .

An excellent site for links concerning technical knowledge of memory management for various operating systems:

http://www.memorymanagement.org .