Data Types Chapter 6: Data Types Lectures # 13. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.

Slides:



Advertisements
Similar presentations
Chapter 22 Implementing lists: linked implementations.
Advertisements

Copyright © 1998 by Addison Wesley Longman, Inc. 1 Chapter 4 Names - Design issues: - Maximum length? - Are connector characters allowed? - Are names case.
Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Chapter 6 Data Types
Names and Bindings.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Garbage Collection CSCI 2720 Spring Static vs. Dynamic Allocation Early versions of Fortran –All memory was static C –Mix of static and dynamic.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
CPSC 388 – Compiler Design and Construction
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
Memory Management. History Run-time management of dynamic memory is a necessary activity for modern programming languages Lisp of the 1960’s was one of.
CS 355 – Programming Languages
1 Day 03 Introduction to C. 2 Memory layout and addresses r s int x = 5, y = 10; float f = 12.5, g = 9.8; char c = ‘r’, d = ‘s’;
ISBN Lecture 06 Data Types. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Lecture 06 Topics Introduction Primitive Data.
Lifetime “The lifetime of a variable is the time during which the variable is bound to a specific memory location.” [p. 219] “…the lifetime of a variable.
CS 330 Programming Languages 11 / 16 / 2006 Instructor: Michael Eckmann.
CS 330 Programming Languages 11 / 13 / 2007 Instructor: Michael Eckmann.
The environment of the computation Declarations introduce names that denote entities. At execution-time, entities are bound to values or to locations:
ISBN 0-321— Chapter 6 Data Types. Copyright © 2007 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
Primitive Data Types: Numbers Strings Ordinal Types Pointers
Lecture 6 Concepts of Programming Languages
Reference Counters Associate a counter with each heap item Whenever a heap item is created, such as by a new or malloc instruction, initialize the counter.
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
ISBN 0-321— Chapter 6 Data Types. Copyright © 2007 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
College of Computer Science and Engineering
CS 330 Programming Languages 11 / 14 / 2006 Instructor: Michael Eckmann.
ISBN 0-321— Chapter 6 Data Types. Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley.
ISBN 0-321— Chapter 6 sections 1-4, 9 Primitive Data Types Numbers Strings Ordinal Types Pointers.
6-1 Chapter 6: Data Types Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types.
Basic Semantics Associating meaning with language entities.
1 Records Record aggregate of data elements –Possibly heterogeneous –Elements/slots are identified by names –Elements in same fixed order in all records.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R F I V E Memory Management.
CPSC 252 Dynamic Memory Allocation Page 1 Dynamic memory allocation Our first IntVector class has some serious limitations the capacity is fixed at MAX_SIZE.
Pointers in C++. 7a-2 Pointers "pointer" is a basic type like int or double value of a pointer variable contains the location, or address in memory, of.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
CS 330 Programming Languages 11 / 11 / 2008 Veterans Day Instructor: Michael Eckmann.
ISBN Chapter 6 Data Types. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Chapter 6 Topics Introduction Primitive Data.
CS 330 Programming Languages 10 / 30 / 2007 Instructor: Michael Eckmann.
ISBN 0-321— Chapter 6 Data Types. Copyright © 2007 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
C H A P T E R S I X Data Types.
Heap storage & Garbage collection Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001.
1 CS Programming Languages Class 09 September 21, 2000.
ISBN Chapter 6 Data Types Pointer Types Reference Types Memory Management.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
Data Types W E E K F O U R. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character String.
Copyright © 2006 Addison-Wesley. All rights reserved. 6-1 Subscript Bindings and Array Categories In some languages the lower bound of the subscript range.
Chapter 6 © 2002 by Addison Wesley Longman, Inc Introduction - Evolution of Data Types: FORTRAN I (1957) - INTEGER, REAL, arrays … Ada (1983) -
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved.2 Primitive Data Types Almost all programming languages.
Copyright © 1998 by Addison Wesley Longman, Inc. 1 Chapter 5 Evolution of Data Types: FORTRAN I (1956) - INTEGER, REAL, arrays … Ada (1983) - User can.
ISBN Chapter 12 Support for Object-Oriented Programming.
Records type city is record -- Ada Name: String (1..10); Country : String (1..20); Population: integer; Capital : Boolean; end record; struct city { --
Recap Resizing the Vector Push_back function Parameters passing Mechanism Primitive Arrays of Constants Multidimensional Arrays The Standard Library string.
Data Types Chapter 6: Data Types Lectures # 11. Topics Introduction Primitive Data Types Character String Types Array Types Associative Arrays Record.
CSC 533: Programming Languages Spring 2016
Object Lifetime and Pointers
Data Types In Text: Chapter 6.
CSC 533: Programming Languages Spring 2015
Chapter 6 – Data Types CSCE 343.
CMP 339/692 Programming Languages Day 14 Tuesday, March 20, 2012
Chapter 6 Data Types.
Records Design Issues: 1. What is the form of references?
Concepts of programming languages
Concepts of programming languages
Complex Data Types One very important measure of the “goodness” of a PL is the capability of its data types to model the problem space variables Design.
Chapter 6 Data Types.
Chapter 6 Data Types.
CSC 533: Programming Languages Spring 2019
Presentation transcript:

Data Types Chapter 6: Data Types Lectures # 13

Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative Arrays Record Types Union Types Pointer and Reference Types

A pointer type variable has a range of values that consists of memory addresses and a special value, nil. The value of nil indicates that a pointer can’t reference any memory cell. Provide the power of indirect addressing  Used in Assembly language programming. Provide a way to manage dynamic memory. A pointer can be used to access a location in the area where storage is dynamically created (usually called a heap). Chapter 6: Data Types 3

Pointer Operations Two fundamental operations: assignment and dereferencing. Assignment is used to set a pointer variable’s value to some useful address. Dereferencing yields the value stored at the location represented by the pointer’s value.  Dereferencing can be explicit or implicit. C++ uses an explicit operation via *. j = *ptr; // sets j to the value located at ptr Implicit dereferencing  Used in Ada pointers, and Java references. Chapter 6: Data Types 4

Pointer Assignment Illustrated The assignment operation j = *ptr; Chapter 6: Data Types 5

Problems with Pointers 1. Dangling pointers (dangerous):  A pointer points to a heap-dynamic variable that has been de-allocated.  Ex: Chapter 6: Data Types 6

Problems with Pointers 2. Lost heap-dynamic variable:  An allocated heap-dynamic variable that is no longer accessible to the user program (often called garbage).  The process of losing heap-dynamic variables is called memory leakage.  Ex: Chapter 6: Data Types 7

Pointers in Pascal Used for dynamic storage management only. Use explicit dereferencing ( p^ ). Dangling pointers and lost objects are possible. Chapter 6: Data Types 8

Pointers in Ada Are called access types. Some dangling pointers are disallowed because dynamic objects can be automatically deallocated at the end of a pointer’s scope. All pointers are initialized to null. Implicit dereferencing is used. The last heap dynamic variable problem is not eliminated by Ada. Chapter 6: Data Types 9

Pointers in C and C++ Extremely flexible but must be used with care. No solution to the pointer problems. Pointers can point at any variable regardless of when it was allocated. Used for dynamic storage management and addressing. Pointer arithmetic is possible. Explicit dereferencing and address-of operators. Chapter 6: Data Types 10

Pointer Arithmetic in C and C++ float stuff[100]; float *p; p = stuff; *(p+5) is equivalent to stuff[5] and p[5] *(p+i) is equivalent to stuff[i] and p[i] Chapter 6: Data Types 11

Evaluation of Pointers Dangling pointers and dangling objects are problems as is heap management. Pointers are like goto 's -- they widen the range of cells that can be accessed by a variable. Pointers or references are necessary for dynamic data structures -- so we can't design a language without them. Chapter 6: Data Types 12

Heap Management A very complex run-time process. Single-size cells vs. variable-size cells. Two approaches to reclaim garbage:  Reference counters (eager approach): Reclamation is gradual.  Garbage collection (lazy approach): Reclamation occurs when the list of variable space becomes empty. Chapter 6: Data Types 13

Reference Counter Reference counters:  Maintain a counter in every cell that store the number of pointers currently pointing at the cell.  Disadvantages: space required, execution time required, complications for cells connected circularly. Chapter 6: Data Types 14

Garbage Collection The run-time system allocates storage cells as requested and disconnects pointers from cells as necessary; garbage collection then begins.  Every heap cell has an extra bit used by collection algorithm.  All cells initially set to garbage.  All pointers traced into heap, and reachable cells marked as not garbage.  All garbage cells returned to list of available cells.  Disadvantages: when you need it most, it works worst (takes most time when program needs most of cells in heap). Chapter 6: Data Types 15