storage_management

storage_management - COP4020 Programming Languages Names,...

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

View Full Document Right Arrow Icon
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan
Background image of page 1

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

View Full DocumentRight Arrow Icon
COP4020 Spring 2011 2 02/20/12 Overview Object storage management Static allocation Stack allocation Heap allocation
Background image of page 2
COP4020 Spring 2011 3 02/20/12 Object Lifetime and Storage Objects (program data and code) have to be stored in memory during their lifetime. In general there are three types of objects in a program The objects that are alive throughout the execution of a program E.g. global variables The objects that are alive within a routine E.g. local variables The objects whose lifetime can be dynamically changed. The objects that are managed by the ‘new/delete’ constructs.
Background image of page 3

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

View Full DocumentRight Arrow Icon
COP4020 Spring 2011 4 02/20/12 Object Lifetime and Storage The three types of objects correspond to thee principal storage allocation mechanisms. Static objects have an absolute storage address that is retained throughout the execution of the program Global variables and data Subroutine code and class method code Stack objects are allocated in last-in first-out order, usually in conjunction with subroutine calls and returns Actual arguments passed by value to a subroutine Local variables of a subroutine Heap objects may be allocated and deallocated at arbitrary times, but require an expensive storage management algorithm Dynamically allocated data in C++. Java class instances are always stored on the heap
Background image of page 4
COP4020 Spring 2011 5 02/20/12 Typical Program and Data Layout in Memory Program code is at the bottom of the memory region (code section) The code section is protected from run-time modification by the OS Static data objects are stored in the static region Stack grows downward Heap grows upward heap stack static data code 0000 Upper addr Virtual memory address space
Background image of page 5

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

View Full DocumentRight Arrow Icon
COP4020 Spring 2011 6 02/20/12 Static Allocation Program code is statically allocated in most implementations of imperative languages Statically allocated variables are history sensitive Global variables keep state during entire program lifetime Static local variables in C/C++ functions keep state across function invocations Static data members are “shared” by objects and keep state during program lifetime Advantage of statically allocated object is the fast access due to absolute addressing of the object Can static allocation be used for local variables? Statically allocated local variables has only one copy of each variable. Cannot deal with the cases when multiple copies of a local varabile are alive!!! When does this happen?
Background image of page 6
COP4020 Spring 2011 7 02/20/12 Static Allocation in Fortran 77 Fortran 77 has no recursion Global and local variables are statically allocated as decided by the compiler Global and local variables are referenced at absolute addresses Avoids overhead of creation and destruction of local objects for
Background image of page 7

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

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

This note was uploaded on 02/20/2012 for the course COP 4020 taught by Professor Engelen during the Spring '11 term at FSU.

Page1 / 22

storage_management - COP4020 Programming Languages Names,...

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

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