Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binding Times Binding is an association between two things Examples:

Similar presentations


Presentation on theme: "Binding Times Binding is an association between two things Examples:"— Presentation transcript:

1 Binding Times Binding is an association between two things Examples:
Name of a variable and its address Name of the operator and its meaning

2 Binding Time Language design time Examples: Control flow constructs
Primitive types Meaning of the operators Syntactical structures of the language

3 Binding Time Language implementation time Examples:
Sizes of primitive data types (int in C and C++) Sizes of stack, heap I/O facilities

4 Binding Time Compile time Examples:
Mapping the code to the machine language Layout of the static data in memory

5 Binding Time Link time Example:
Linkage between different modules that make up a program (when you use a function such a strcpy in your code, the code of the strcpy is not being linked to your main code until the link time)

6 Binding Time Run Time Examples:
Local variables are bound at the run time Virtual function are bound at the run time

7 Binding time We normally refer to the binding that occurs before the run time as static binding and the binding that occurs at the run time as a dynamic binding

8 Binding Time Static binding Efficiency Flexibility Dynamic binding

9 Object Lifetime Static Objects – have an address that does not get changed through out the execution of the program. Static Objects exist all the time Stack Objects – are created normally when the subroutine in which they are defined is being invoked. Heap Objects – are created on demand from the free storage using something like new and delete

10 Stack Based Variables The variables that are defined in the functions are being created and put on the stack when the function in which they are defined is being invoked. Another words, we are creating those variables on the stack. When the function returns, those variables are being removed from the stack.

11 Allocation Each instance of the subroutine is represented on the stack by a frame. Each frame is going to contain the following information: Arguments Return values Local variables Static link Dynamic link

12 Frame

13 Recursion One of the main design decisions that is being made by the language designers is whether to allow recursion. If the recursion is not allowed do we really need the stack? Why or why not? What are the advantages and disadvantages of each solution?

14 Heap Heap is the region where the space is being allocated and deallocated by new and delete

15 Fragmentation The major issue with heap allocation is fragmentation
Internal fragmentation occurs when the allocated block of memory is bigger than the memory needed. Why is this bad? External fragmentation occurs when the free blocks are scattered through out the memory. Why is this bad?

16 Fragmentation

17 Allocation Algorithms
First fit – might not be optimal, but is very fast Best fit – closer to be optimal, but is more expensive Different block sizes lists can be used to speed up the search of the free block. Two examples are buddy system in which the power of two is used and Fibonacci heaps in which Fibonacci numbers are being used.

18 Scope The scope of the variable is the area of the program in which a given variable is visible Statically scoped languages define the scope of the variable at the compile time Dynamically scoped languages define the scope of the variable at the run time

19 Static Scope

20 Static Link

21 Dynamic Scope Dynamic Scope
- Based on calling sequences of program units, not their textual layout (temporal versus spatial) - References to variables are connected to declarations by searching back through the chain of subprogram calls that forced execution to this Point

22 Dynamic Scope MAIN begin declaration of x SUB1 declaration of x -
call SUB2 end SUB2 reference to x - call SUB1

23 Dynamic Scope MAIN calls SUB1 SUB1 calls SUB2 SUB2 uses x
Static scoping - reference to x is to MAIN's x Dynamic scoping - reference to x is to SUB1's x


Download ppt "Binding Times Binding is an association between two things Examples:"

Similar presentations


Ads by Google