Semantics of Arrays and Pointers By: M. Reza Heydarian Introduction Pointers Arrays Semantics of Arrays Semantics of Pointers.

Slides:



Advertisements
Similar presentations
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 11 Memory Management C makes it easy to shoot.
Advertisements

CHP-5 LinkedList.
Chapter 6 Data Types
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
Names and Bindings.
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
Informática II Prof. Dr. Gustavo Patiño MJ
CSC321: Programming Languages 11-1 Programming Languages Tucker and Noonan Chapter 11: Memory Management 11.1 The Heap 11.2 Implementation of Dynamic Arrays.
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.
Chapter 9. 2 Objectives You should be able to describe: Addresses and Pointers Array Names as Pointers Pointer Arithmetic Passing Addresses Common Programming.
Chapter 10 Storage management
CSE 2501 Review Declaring a variable allocates space for the type of datum it is to store int x; // allocates space for an int int *px; // allocates space.
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
ISBN Chapter 6 Data Types: Structured types.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 10 Function Implementation In theory, there.
Run-Time Storage Organization
The Concept of Variables
Pointers. Addresses in Memory When a variable is declared, enough memory to hold a value of that type is allocated for it at an unused memory location.
Lecture 2 Pointers Pointers with Arrays Dynamic Memory Allocation.
Review on pointers and dynamic objects. Memory Management  Static Memory Allocation  Memory is allocated at compiling time  Dynamic Memory  Memory.
Chapter 9: Subprogram Control
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
Pointers Applications
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
1/25 Pointer Logic Changki PSWLAB Pointer Logic Daniel Kroening and Ofer Strichman Decision Procedure.
Overview Working directly with memory locations is beneficial. In C, pointers allow you to: change values passed as arguments to functions work directly.
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 10. Pointers & Dynamic Data Structures.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 2.
Chapter 5 – Dynamic Data Structure Par1: Abstract Data Type DATA STRUCTURES & ALGORITHMS Teacher: Nguyen Do Thai Nguyen
ISBN Chapter 5 Names, Bindings, and Scopes.
Storage Bindings Allocation is the process by which the memory cell or collection of memory cells is assigned to a variable. These cells are taken from.
Introduction A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in.
Basic Semantics Associating meaning with language entities.
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.
C++ Data Types Structured array struct union class Address pointer reference Simple IntegralFloating char short int long enum float double long double.
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.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
Lecture – Pointers1 C++ Pointers Joseph Spring/Bob Dickerson School of Computer Science Operating Systems and Computer Networks Based on notes by Bob Dickerson.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved This Weeks Topics: Pointers (continued)  Modify C-String through a function call 
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
Data Structures in C++ Pointers & Dynamic Arrays Shinta P.
A FIRST BOOK OF C++ CHAPTER 8 ARRAYS AND POINTERS.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
C++ for Engineers and Scientists Second Edition Chapter 12 Pointers.
CSI 3125, Data Types, page 1 Data types Outline Primitive data types Structured data types Strings Enumerated types Arrays Records Pointers Reading assignment.
Windows Programming Lecture 03. Pointers and Arrays.
POINTERS AND MEMORY ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED BY NANCY M. AMATO AND JORY DENNY 1.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part R2. Elementary Data Structures.
Records type city is record -- Ada Name: String (1..10); Country : String (1..20); Population: integer; Capital : Boolean; end record; struct city { --
Data Types Chapter 6: Data Types Lectures # 13. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.
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.
Memory Management Functions
Data Types In Text: Chapter 6.
Type Checking, and Scopes
Names, Bindings, and Scopes
Pointers And Memory Acknowledgement: THE Slides are Prepared FROM SLIDES PROVIDED By NANCY M. AMATO AND Jory Denny.
UNIT V Run Time Environments.
Dynamic Memory.
Names, Bindings, and Scopes
Run-time environments
Presentation transcript:

Semantics of Arrays and Pointers By: M. Reza Heydarian Introduction Pointers Arrays Semantics of Arrays Semantics of Pointers

Introduction (Memory Management Overview) -Three Categories of Memory 1- Static Memory For values whose storage requirement:. Are known before runtime. Remain constant during running program 2- Run-time Stack - For dispatching active methods: Their local variables and parameter-argument linkages - Structure of stack is predictable and regular 3- Heap

Heap -Least structured of the three memory categories -Contain all other values that are dynamically allocated during run-time -Structure is far less predictable and regular -Becomes fragmented -Active memory blocks are not contiguous -Heap blocks are accessed indirectly using pointers (pointers are located in stack or heap)

Figure of Memory -addresses {0,…,n} called the program’s address space -h and n are initially defined at the beginning of run-time

Using two sets to manage Memory 1- Environment (  m ): - m is a method.-  m is set of pairs: 2- Memory (  ) -Each pair: -Non-allocate locations are marked unused -Allocated location without value are marked undefined -Use overriding union to change this set

An Example of Sets

Pointers -Memory address (reference) -Indirection in referencing a value or a collection of value -Bane of reliable software development -Programmer must restore heap blocks -Some language(e.g.Java) remove explicit pointers

Arrays -Ordered sequences of values with same type -May have any number of dimensions -Its memory is dynamically allocated -Share the same scope rules as simple variables -In different language may be:.allocated space in either static, stack, or heap area.different indexing (e.g. C,C++,Java all use 0-origin indexing).different way to locate element in memory (e.g. row major order)

A semantic view of Memory in definition of Array

Semantic of arrays -By Jay semantic function.one dimensional array.heap allocation strategies.are accessed by a pointer in the stack -Using two functions:.new: find a contiguous unused block.delete

new and delete functions

allocate function

deallocate function

Semantic of expression evaluation

Denotational semantics of Array Hoare’s view: Array values are functions (Assume values of elements are Nat. Type)

Denotational semantics of Array(cont’) A new semantic function: Some semantic equations: - Array Variables

Denotational semantics of Array(cont’) - Array Application - Array Assignment - Array Declaration

Semantics of Pointers -Basic operations on references (Pointers):. Allocation r = ref 5; |> r : Ref Nat. Dereferencing !r;|> 5 : Nat. Assignment r := 7;|> unit : Unit

Pointers and Aliasing r = s = r => s = 13

Pointers and Compound Types We can create references to any type. Including function. e.g. Array of numbers (use references to function). e.g. Type is: Ref (Nat  Nat)

Operational Semantics Typing Evaluation Store Typing

Typing

Evaluation Change relation from t  t’ to t|  t’|  ’ Where  and  ’ are the starting and ending states of the store

Set of values and terms

Rules

Rules (cont’)

Store Typing

References 1- Programming Languages: Principles and Paradigms Allen Tucker and Robert Noonan. 2- Types and Programming Languages Benjamin C. Pierce 3- Theory of Programming Languages John C. Reynolds