SlideShare ist ein Scribd-Unternehmen logo
1 von 37
By-
Garima Jain
   Abstract Data Type
   Information Hiding
   Encapsulation
   Type Definition
   Static and Stack-Based Storage Management
   Fixed and Variable size heap Storage Management
   Garbage Collection
An abstract data type is:

A set of data objects,
A set of abstract operations on those data
objects
Encapsulation of the whole in such a way that
the user of the data object cannot manipulate data
objects of the type except by the use of operation
defined.
When information is encapsulated in an abstraction,
it means that the user of the abstraction

   1. Does not need to know the hidden
   information in order to use the abstraction

   2. Is not permitted to directly use or
   manipulate the hidden information even if
   desiring to do so.
Subprograms

Type definitions
   Encapsulation by Subprograms
     Subprograms as abstract operations
     Subprogram definition and invocation


   Type Definitions
Subprogram:
A mathematical function that maps each particular set of
arguments into a particular set of results.
   the name of the subprogram
   the signature of the subprogram: arguments, results
   the action performed by the subprogram
Type checking: similar to type checking for primitive
operations.

Difference: types of operands and results are
explicitly stated in the program
   Implicit arguments in the form of non-local
    variables
   Implicit results – changes in non-local variables
   History sensitiveness – results may depend on
    previous executions
   Uses the data structures and operation provided by the
    language
   Defined by the subprogram body
     Local data declarations
     Statements defining the actions over the data
   Interface with the user: arguments and returned result
A simple (but not efficient) approach:
   Each time the subprogram is invoked, a copy
   of its executable statements, constants and
   local variables is created.

A better approach:
   The executable statements and constants are
   invariant part of the subprogram - they do
   not need to be copied for each execution of the
   subprogram.
Subprogram definition: the set of statements
constituting the body of the subprogram.
Static property; the only information available
during translation.

Subprogram activation: a data structure (record)
created upon invoking the subprogram.
It exists while the subprogram is being executed.
After that the activation record is destroyed.
The definition serves as a template to create the activation
A single copy is used for all activations of the subprogram.
This copy is called code segment. This is the static part.

The activation record contains only the parameters,
results and local data.
This is the dynamic part. It has same structure, but
different values for the variables.
Type definitions are used for definition of a new type in
terms of already defined type.

They do not define a complete abstract data type, because the
definitions of the operations are not included.

Format:    typedef definition name

Meaning: definition is already defined type.
           name is substituted with definition.
typedef int key_type;
key_type key1, key2;

struct rational_number
       {int numerator, denominator;}

typedef rational_number rational;

rational r1, r2;
Two questions to be answered:

•When are two types the same?

•When do 2 objects have the same value?
Two data types are considered equivalent only if
they have the same name.



Issues
Every object must have an assigned type, there can
be no anonymous types.

A singe type definition must serve all or large parts
of a program.
Two data types are considered equivalent if they define
data objects that have the same internal components.

Issues
• Do components need to be exact duplicates?
• Can field order be different in records?
• Can field sizes vary?
Two objects are equal if each member in one object
is identical to the corresponding member of the
other object.



The compiler has no way to know how to compare data
values of user-defined type. It is the task of the
programmer that has defined that particular data type to
define also the operations with the objects of that type.
Parameters allow for user to prescribe the size of
data types needed – array sizes.

Implementation

Type definition with parameters is used as a
template as any other type definition during
compilation.
Different features in a language causes different
storage management techniques to be used.
   FORTRAN: no recursive calls, no dynamic
   storage management.
   Pascal: stack-based storage management.
   LISP: garbage collection.
   Language implementers decide about the
   details.
   Programmers don’t know about it.
   Initial allocation
   Recovery
   Compaction and reuse
Static allocation :
Allocation during translation that remains fixed
throughout execution.
 Does not allow recursive subprograms
   Simplest
   static allocation
   no run-time storage management
   no concern for recovery and reuse
   efficient
   in COBOL and FORTRAN
   In FORTRAN
     each subprogram is compiled separately,
     the code segment includes an activation record
         compiled program,
         its data areas,
         return point location,
         miscellaneous items of system data.
   Simplest run-time storage management technique.
   Based on the nested last in first out structure in
    subprograms calls and returns.
   Automatic compaction.
   In Pascal : a single central stack of activation records,
    and a statically allocated area for subprogram code
    segments and system programs.
Memory used for dynamic allocation of data objects
in somewhat unstructured manner is called heap
storage.

                    OS

                  HEAP




                  STACK
Tasks:
    allocation,
    recovery,
          dangling references
          garbage collection

     compaction,
     reuse

Fixed size elements
Variable size elements
   A heap is a block of storage within which pieces are
    allocated and freed in some relatively unstructured
    manner.
   Need for heap , when a language permits storage to
    be allocated and freed at execution time.
   Fixed size elements allocated => no need for
    compaction.
The problem: identification of reusable element,
  solutions:
 Explicit return by programmer or system.

   Natural, but cause        garbage and dangling
    reference.
 Reference counts.

   Cost of maintaining.
   popular with parallel processing systems.
 Garbage collection.
   Dangling references more dangerous
   Two stages
     Mark
       garbage collection bit, set off if it is active.
     Sweep
       links the “on” elements to the free list.
    When is a heap element active?
       There is a pointer to it from
         outside the heap
         another active heap element
   Three critical assumptions
     any active element must be reachable by a chain
      of pointers beginning outside the heap.
     It must be possible to identify every pointer
      outside the heap that points to an element inside
      the heap.
     It must be possible to identify within any active
      heap element the fields that contain pointers to
      other heap elements.
   More difficult
   if space for programmer defined data structures      is
    sequential, like arrays or activation records.
   Major difficulty : reuse of recovered space.
   Initial allocation and reuse.
   reuse directly from a free-space list.
     First-fit method
     best-fit method
    keeping free-space list in size order.
   Recovery with variable-size blocks.
     In first word of each block: a length indicator.
   Compaction and memory fragmentation problem.
   Compaction approaches:
     Partial compaction
       only adjacent free blocks
     Full compaction
       active blocks may be shifted
Unit 5

Weitere ähnliche Inhalte

Was ist angesagt?

Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysisDattatray Gandhmal
 
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDA
Push Down Automata (PDA) | TOC  (Theory of Computation) | NPDA | DPDAPush Down Automata (PDA) | TOC  (Theory of Computation) | NPDA | DPDA
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDAAshish Duggal
 
The role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designThe role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designSadia Akter
 
Scheduling Definition, objectives and types
Scheduling Definition, objectives and types Scheduling Definition, objectives and types
Scheduling Definition, objectives and types Maitree Patel
 
Scope - Static and Dynamic
Scope - Static and DynamicScope - Static and Dynamic
Scope - Static and DynamicSneh Pahilwani
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSvampugani
 
Single pass assembler
Single pass assemblerSingle pass assembler
Single pass assemblerBansari Shah
 
Unit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesUnit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesVasavi College of Engg
 
Directed Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksDirected Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksMohammad Vaseem Akaram
 
14 relationship between processes
14 relationship between processes14 relationship between processes
14 relationship between processesmyrajendra
 
Elements of dynamic programming
Elements of dynamic programmingElements of dynamic programming
Elements of dynamic programmingTafhim Islam
 
Evolutionary models
Evolutionary modelsEvolutionary models
Evolutionary modelsPihu Goel
 

Was ist angesagt? (20)

Unit 4 sp macro
Unit 4 sp macroUnit 4 sp macro
Unit 4 sp macro
 
Finite automata-for-lexical-analysis
Finite automata-for-lexical-analysisFinite automata-for-lexical-analysis
Finite automata-for-lexical-analysis
 
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDA
Push Down Automata (PDA) | TOC  (Theory of Computation) | NPDA | DPDAPush Down Automata (PDA) | TOC  (Theory of Computation) | NPDA | DPDA
Push Down Automata (PDA) | TOC (Theory of Computation) | NPDA | DPDA
 
The role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler designThe role of the parser and Error recovery strategies ppt in compiler design
The role of the parser and Error recovery strategies ppt in compiler design
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Specification-of-tokens
Specification-of-tokensSpecification-of-tokens
Specification-of-tokens
 
Scheduling Definition, objectives and types
Scheduling Definition, objectives and types Scheduling Definition, objectives and types
Scheduling Definition, objectives and types
 
Scope - Static and Dynamic
Scope - Static and DynamicScope - Static and Dynamic
Scope - Static and Dynamic
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Single pass assembler
Single pass assemblerSingle pass assembler
Single pass assembler
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Unit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesUnit 2 Principles of Programming Languages
Unit 2 Principles of Programming Languages
 
Directed Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksDirected Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocks
 
Single Pass Assembler
Single Pass AssemblerSingle Pass Assembler
Single Pass Assembler
 
14 relationship between processes
14 relationship between processes14 relationship between processes
14 relationship between processes
 
Elements of dynamic programming
Elements of dynamic programmingElements of dynamic programming
Elements of dynamic programming
 
Evolutionary models
Evolutionary modelsEvolutionary models
Evolutionary models
 
COMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time EnvironmentsCOMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time Environments
 

Ähnlich wie Unit 5

Tcs NQTExam technical questions
Tcs NQTExam technical questionsTcs NQTExam technical questions
Tcs NQTExam technical questionsAniketBhandare2
 
Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptx
Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptxKripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptx
Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptxsg4795
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1ReKruiTIn.com
 
Technical_Interview_Questions.pdf
Technical_Interview_Questions.pdfTechnical_Interview_Questions.pdf
Technical_Interview_Questions.pdfadityashukla939020
 
22827361 ab initio-fa-qs
22827361 ab initio-fa-qs22827361 ab initio-fa-qs
22827361 ab initio-fa-qsCapgemini
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialscesarmendez78
 
CD CLASS NOTES- UNIT-4.docx
CD CLASS NOTES- UNIT-4.docxCD CLASS NOTES- UNIT-4.docx
CD CLASS NOTES- UNIT-4.docxKANDE ARCHANA
 
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.docabdulhaq467432
 
220 runtime environments
220 runtime environments220 runtime environments
220 runtime environmentsJ'tong Atong
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++Reddhi Basu
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basicsvamshimahi
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory ManagementRahul Jamwal
 

Ähnlich wie Unit 5 (20)

Tcs NQTExam technical questions
Tcs NQTExam technical questionsTcs NQTExam technical questions
Tcs NQTExam technical questions
 
Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptx
Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptxKripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptx
Kripanshu MOOC PPT - Kripanshu Shekhar Jha (1).pptx
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
Technical_Interview_Questions.pdf
Technical_Interview_Questions.pdfTechnical_Interview_Questions.pdf
Technical_Interview_Questions.pdf
 
My c++
My c++My c++
My c++
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
Question bank unit i
Question bank unit iQuestion bank unit i
Question bank unit i
 
22827361 ab initio-fa-qs
22827361 ab initio-fa-qs22827361 ab initio-fa-qs
22827361 ab initio-fa-qs
 
Unit 2
Unit 2Unit 2
Unit 2
 
Abap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorialsAbap object-oriented-programming-tutorials
Abap object-oriented-programming-tutorials
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
memory
memorymemory
memory
 
CD CLASS NOTES- UNIT-4.docx
CD CLASS NOTES- UNIT-4.docxCD CLASS NOTES- UNIT-4.docx
CD CLASS NOTES- UNIT-4.docx
 
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
7.-Download_CS201-Solved-Subjective-with-Reference-by-Aqib.doc
 
VB.net
VB.netVB.net
VB.net
 
220 runtime environments
220 runtime environments220 runtime environments
220 runtime environments
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++
 
Object oriented basics
Object oriented basicsObject oriented basics
Object oriented basics
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory Management
 
L035478083
L035478083L035478083
L035478083
 

Unit 5

  • 2. Abstract Data Type  Information Hiding  Encapsulation  Type Definition  Static and Stack-Based Storage Management  Fixed and Variable size heap Storage Management  Garbage Collection
  • 3. An abstract data type is: A set of data objects, A set of abstract operations on those data objects Encapsulation of the whole in such a way that the user of the data object cannot manipulate data objects of the type except by the use of operation defined.
  • 4. When information is encapsulated in an abstraction, it means that the user of the abstraction 1. Does not need to know the hidden information in order to use the abstraction 2. Is not permitted to directly use or manipulate the hidden information even if desiring to do so.
  • 6. Encapsulation by Subprograms  Subprograms as abstract operations  Subprogram definition and invocation  Type Definitions
  • 7. Subprogram: A mathematical function that maps each particular set of arguments into a particular set of results.
  • 8. the name of the subprogram  the signature of the subprogram: arguments, results  the action performed by the subprogram
  • 9. Type checking: similar to type checking for primitive operations. Difference: types of operands and results are explicitly stated in the program
  • 10. Implicit arguments in the form of non-local variables  Implicit results – changes in non-local variables  History sensitiveness – results may depend on previous executions
  • 11. Uses the data structures and operation provided by the language  Defined by the subprogram body  Local data declarations  Statements defining the actions over the data  Interface with the user: arguments and returned result
  • 12. A simple (but not efficient) approach: Each time the subprogram is invoked, a copy of its executable statements, constants and local variables is created. A better approach: The executable statements and constants are invariant part of the subprogram - they do not need to be copied for each execution of the subprogram.
  • 13. Subprogram definition: the set of statements constituting the body of the subprogram. Static property; the only information available during translation. Subprogram activation: a data structure (record) created upon invoking the subprogram. It exists while the subprogram is being executed. After that the activation record is destroyed.
  • 14. The definition serves as a template to create the activation
  • 15. A single copy is used for all activations of the subprogram. This copy is called code segment. This is the static part. The activation record contains only the parameters, results and local data. This is the dynamic part. It has same structure, but different values for the variables.
  • 16. Type definitions are used for definition of a new type in terms of already defined type. They do not define a complete abstract data type, because the definitions of the operations are not included. Format: typedef definition name Meaning: definition is already defined type. name is substituted with definition.
  • 17. typedef int key_type; key_type key1, key2; struct rational_number {int numerator, denominator;} typedef rational_number rational; rational r1, r2;
  • 18. Two questions to be answered: •When are two types the same? •When do 2 objects have the same value?
  • 19. Two data types are considered equivalent only if they have the same name. Issues Every object must have an assigned type, there can be no anonymous types. A singe type definition must serve all or large parts of a program.
  • 20. Two data types are considered equivalent if they define data objects that have the same internal components. Issues • Do components need to be exact duplicates? • Can field order be different in records? • Can field sizes vary?
  • 21. Two objects are equal if each member in one object is identical to the corresponding member of the other object. The compiler has no way to know how to compare data values of user-defined type. It is the task of the programmer that has defined that particular data type to define also the operations with the objects of that type.
  • 22. Parameters allow for user to prescribe the size of data types needed – array sizes. Implementation Type definition with parameters is used as a template as any other type definition during compilation.
  • 23. Different features in a language causes different storage management techniques to be used. FORTRAN: no recursive calls, no dynamic storage management. Pascal: stack-based storage management. LISP: garbage collection. Language implementers decide about the details. Programmers don’t know about it.
  • 24. Initial allocation  Recovery  Compaction and reuse
  • 25. Static allocation : Allocation during translation that remains fixed throughout execution.  Does not allow recursive subprograms
  • 26. Simplest  static allocation  no run-time storage management  no concern for recovery and reuse  efficient  in COBOL and FORTRAN
  • 27. In FORTRAN  each subprogram is compiled separately,  the code segment includes an activation record  compiled program,  its data areas,  return point location,  miscellaneous items of system data.
  • 28. Simplest run-time storage management technique.  Based on the nested last in first out structure in subprograms calls and returns.  Automatic compaction.  In Pascal : a single central stack of activation records, and a statically allocated area for subprogram code segments and system programs.
  • 29. Memory used for dynamic allocation of data objects in somewhat unstructured manner is called heap storage. OS HEAP STACK
  • 30. Tasks: allocation, recovery, dangling references garbage collection compaction, reuse Fixed size elements Variable size elements
  • 31. A heap is a block of storage within which pieces are allocated and freed in some relatively unstructured manner.  Need for heap , when a language permits storage to be allocated and freed at execution time.  Fixed size elements allocated => no need for compaction.
  • 32. The problem: identification of reusable element, solutions:  Explicit return by programmer or system.  Natural, but cause garbage and dangling reference.  Reference counts.  Cost of maintaining.  popular with parallel processing systems.  Garbage collection.
  • 33. Dangling references more dangerous  Two stages  Mark  garbage collection bit, set off if it is active.  Sweep  links the “on” elements to the free list. When is a heap element active?  There is a pointer to it from  outside the heap  another active heap element
  • 34. Three critical assumptions  any active element must be reachable by a chain of pointers beginning outside the heap.  It must be possible to identify every pointer outside the heap that points to an element inside the heap.  It must be possible to identify within any active heap element the fields that contain pointers to other heap elements.
  • 35. More difficult  if space for programmer defined data structures is sequential, like arrays or activation records.  Major difficulty : reuse of recovered space.  Initial allocation and reuse.  reuse directly from a free-space list.  First-fit method  best-fit method keeping free-space list in size order.  Recovery with variable-size blocks.  In first word of each block: a length indicator.  Compaction and memory fragmentation problem.
  • 36. Compaction approaches:  Partial compaction  only adjacent free blocks  Full compaction  active blocks may be shifted