Download presentation
Presentation is loading. Please wait.
Published byPaul Skinner Modified over 9 years ago
1
Semantics of Arrays and Pointers By: M. Reza Heydarian Introduction Pointers Arrays Semantics of Arrays Semantics of Pointers
2
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
3
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)
4
Figure of Memory -addresses {0,…,n} called the program’s address space -h and n are initially defined at the beginning of run-time
5
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
6
An Example of Sets
7
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
9
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)
10
A semantic view of Memory in definition of Array
11
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
12
new and delete functions
13
allocate function
14
deallocate function
15
Semantic of expression evaluation
16
Denotational semantics of Array Hoare’s view: Array values are functions (Assume values of elements are Nat. Type)
17
Denotational semantics of Array(cont’) A new semantic function: Some semantic equations: - Array Variables
18
Denotational semantics of Array(cont’) - Array Application - Array Assignment - Array Declaration
19
Semantics of Pointers -Basic operations on references (Pointers):. Allocation r = ref 5; |> r : Ref Nat. Dereferencing !r;|> 5 : Nat. Assignment r := 7;|> unit : Unit
20
Pointers and Aliasing r = s = r => s = 13
21
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)
22
Operational Semantics Typing Evaluation Store Typing
23
Typing
24
Evaluation Change relation from t t’ to t| t’| ’ Where and ’ are the starting and ending states of the store
25
Set of values and terms
26
Rules
27
Rules (cont’)
28
Store Typing
29
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.