Download presentation
Presentation is loading. Please wait.
Published byStuart Sutton Modified over 9 years ago
1
1 Binding Time and Storage Allocation (Section 3.1-3.2) CSCI 431 Programming Languages Fall 2003 A modification of slides developed by Felix Hernandez-Campos at UNC Chapel Hill
2
2 Review: Compilation/Interpretation Compiler or Interpreter Translation Execution Source Code Target Code Interpre-tation
3
3 Phases of Compilation
4
4 High-Level Programming Languages Two main goals:Two main goals: –Machine independence –Ease of programming High-level programming languages are independent of any particular instruction setHigh-level programming languages are independent of any particular instruction set –But compilation to assembly code requires a target instruction set –There is a trade-off between machine independence and efficiency »E.g. Java vs. C
5
5 Ease of Programming The driving problem in programming language designThe driving problem in programming language design The rest of this classThe rest of this class –Naming –Control Flow –Types –Subroutines –Object Orientation –Concurrency –Functional Programming –Declarative Programming ProgrammingLanguage
6
6 Naming Naming is the process by which the programmer associates a name with a potentially complicated program fragmentNaming is the process by which the programmer associates a name with a potentially complicated program fragment –The goal is to hide complexity –Programming languages use name to designate variables, types, classes, methods, operators,… Naming provides abstractionNaming provides abstraction –E.g. Mathematics is all about the formal notation (i.e. naming) that lets us explore more and more abstract concepts
7
7 Control and Data Abstraction Control abstraction allows the programmer to hide an arbitrarily complicated code behind a simple interfaceControl abstraction allows the programmer to hide an arbitrarily complicated code behind a simple interface –Subroutines –Modules Data Abstraction allows the programmer to hide data representation details behind abstract operationsData Abstraction allows the programmer to hide data representation details behind abstract operations –ADTs –Classes
8
8 Binding Time A binding is an association between two thingsA binding is an association between two things –E.g. Name of an object and the object Binding time is the time at which a binding is createdBinding time is the time at which a binding is created –Language design time –Language implementation –Program writing time –Compile Time –Link Time –Load Time –Run Time
9
9 Binding Time Impact Binding times have a crucial impact in programming languagesBinding times have a crucial impact in programming languages –They are a fundamental design decision In general, early binding is associated with greater efficiencyIn general, early binding is associated with greater efficiency –E.g. compilers translate a program once, interpreters translate it every time it is run In general, late binding is associated with greater flexibilityIn general, late binding is associated with greater flexibility –E.g. Class method vs. Subroutine Compiled languages tend to bind names earlier than interpreted languagesCompiled languages tend to bind names earlier than interpreted languages
10
10 Events in the life of a bindingEvents in the life of a binding –Creation –Destruction »A binding to an object that no longer exists is called a dangling reference –Deactivation and Reactivation Object Lifetime Events in the life of an objectEvents in the life of an object –Creation –Destruction
11
11 Storage Allocation Mechanisms In static allocation, objects are given an absolute address that is retained throughout the program’s executionIn static allocation, objects are given an absolute address that is retained throughout the program’s execution –E.g. Global variables, Non-recursive Subroutine Parameters, constant literals, run-time tables –Some objects are placed in protected, read-only memory
12
12 Static Allocation
13
13 Storage Allocation Mechanisms In static allocation, (static) objects are given an absolute address that is retained throughout the program’s executionIn static allocation, (static) objects are given an absolute address that is retained throughout the program’s execution –E.g. Global variables, Non-recursive Subroutine Parameters In stack-based allocation, (stack) objects are allocated in last-in, first-out data structure, a stack.In stack-based allocation, (stack) objects are allocated in last-in, first-out data structure, a stack. –E.g. Recursive subroutine parameters
14
14 Stack-based Allocation
15
15 Storage Allocation Mechanisms In static allocation, (static) objects are given an absolute address that is retained throughout the program’s executionIn static allocation, (static) objects are given an absolute address that is retained throughout the program’s execution –E.g. Global variables, Non-recursive Subroutine Parameters In stack-based allocation, (stack) objects are allocated in last-in, first-out data structure, a stack.In stack-based allocation, (stack) objects are allocated in last-in, first-out data structure, a stack. –E.g. Subroutine parameters In heap-based allocation, (heap) objects may be allocated and deallocated at arbitrary timesIn heap-based allocation, (heap) objects may be allocated and deallocated at arbitrary times –E.g. objects created with C++ new and delete
16
16 Heap-based Allocation The heap is a region of storage in which blocks of memory can be allocated and deallocatedThe heap is a region of storage in which blocks of memory can be allocated and deallocated –This not the heap data structure
17
17 Heap Space Management In general, the heap is allocated sequentiallyIn general, the heap is allocated sequentially This creates space fragmentation problemsThis creates space fragmentation problems –Internal fragmentation »If size of object to allocated is smaller than the size of the memory chunk available in the heap –External fragmentation »If size of object to allocated is not larger than the size of the available heap, but the available space in the heap is scattered through the heap in such a way that no contiguous allocation is possible Automatic deallocation after an object has no bindings is called garbage collectionAutomatic deallocation after an object has no bindings is called garbage collection –E.g. Java, Ada, Scheme, SmallTalk, etc.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.