0% found this document useful (0 votes)
2 views6 pages

PPL Chapter 5

Uploaded by

uckoojoyeeta24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

PPL Chapter 5

Uploaded by

uckoojoyeeta24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Names and Referencing Environments


Names:
 Identifiers: Names that reference variables, constants, functions, etc.

o Example: int age = 25; here, age is the name.


 Binding: The association between a name and an entity (like memory location or value).
 Name Resolution: The process of finding what a name refers to in a given scope or context.
Referencing Environment:
 Static Referencing Environment:

o Defined by the textual structure of the program (lexical scope).


o Example:

 x is resolved based on its declaration during compilation.

Dynamic Referencing Environment:


 Depends on the sequence of function calls during runtime.
 Example (in pseudo-code using dynamic scoping):

2. Static, Dynamic, and Block Structure


Static Structure:
 The structure visible in the source code.
 Example:
 The scope of y is statically determined by the {} block.
Dynamic Structure:
 Determined by execution flow. It may involve loops, recursion, or conditionals.
 Example:

Block Structure:
 Programs are divided into blocks with their own scope.
 Example:

3. Local Data and Local Referencing Environments


 Local Data:
o Variables declared within a function or block.
o Example:
Local Referencing Environment:
 Includes local variables and variables from enclosing scopes (in languages supporting closures).
 Example in Python:

4. Dynamic and Static Scope of Shared Data


Static Scope:

 Variables are resolved based on their declaration.


 Example:

Dynamic Scope:

 Resolved by searching the call stack at runtime.


 Example:

5. Parameters and Their Transmission


Call by Value:
 A copy of the argument is passed.
 Example:
Call by Reference:

 The address of the argument is passed, allowing direct modification.


 Example:

Call by Value-Result:
 A copy is passed, but changes are written back.

 Example:

Call by Name:
 Re-evaluates the argument each time it’s used.
 Example (conceptually similar to lazy evaluation in functional programming).

6. Tasks and Shared Data

 Tasks: Threads or processes running concurrently.


 Shared Data Issues:
o Race Conditions: Multiple tasks accessing/modifying shared data simultaneously.
o Example: Two threads updating a global counter without synchronization.

 Solutions:
o Mutexes
o Semaphores
o Atomic operations

7. Storage Requirements for Run-Time Elements


 Code Segment: Stores executable instructions.
 Stack Segment: Handles function calls and local variables.
 Heap Segment: Manages dynamic allocations.
 Example:

8. Storage Management
Program-Controlled Storage:
 Manually handled by programmers.
 Example: malloc and free in C.

 Risks: Memory leaks and dangling pointers.


System-Controlled Storage:
 Automatically managed, e.g., garbage collection in Java.

9. Static and Stack-Based Storage Management

Static Storage:
 Pre-allocated.
 Example:
Stack-Based Storage:

 Allocated and deallocated during runtime.


 Example:

10. Fixed-Size and Variable-Size Heap Storage


Fixed-Size:
 Allocates blocks of a fixed size.

 Suitable for uniform objects.


Variable-Size:
 Dynamic allocation for diverse object sizes.
 Managed using algorithms like best-fit or buddy systems.

You might also like