Simulated Pointers Limitations Of Java Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.

Slides:



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

Data Structures ADT List
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Carnegie Mellon 1 Dynamic Memory Allocation: Basic Concepts : Introduction to Computer Systems 17 th Lecture, Oct. 21, 2010 Instructors: Randy Bryant.
David Notkin Autumn 2009 CSE303 Lecture 13 This space for rent.
Dynamic Memory Allocation I Topics Basic representation and alignment (mainly for static memory allocation, main concepts carry over to dynamic memory.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Garbage Collection What is garbage and how can we deal with it?
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Garbage Collection  records not reachable  reclaim to allow reuse  performed by runtime system (support programs linked with the compiled code) (support.
Memory Management & Method Calls in Java Program Execution © Allan C. Milne v
CPSC 388 – Compiler Design and Construction
CSC321: Programming Languages 11-1 Programming Languages Tucker and Noonan Chapter 11: Memory Management 11.1 The Heap 11.2 Implementation of Dynamic Arrays.
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 1114: Data Structures – memory allocation Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
CS 1114: Data Structures – Implementation: part 1 Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Completing the Linked Implementation of a List Chapter 7 Slides by Steve Armstrong LeTourneau University Longview, TX  2007,  Prentice Hall.
Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Memory Allocation and Garbage Collection. Why Dynamic Memory? We cannot know memory requirements in advance when the program is written. We cannot know.
Linked lists and memory allocation Prof. Noah Snavely CS1114
Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.
Chapter 3: Arrays, Linked Lists, and Recursion
Garbage Collection CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
L.Chen1 Chapter 3 DATA REPRESENTATION(2) L.Chen A Chain Iterator Class A Chain Iterator Class ( 遍历器类 )  An iterator permits.
Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.
Linear List Linked Representation. Linked Representation list elements are stored, in memory, in an arbitrary order explicit information (called a link)
1 CSC 222: Computer Programming II Spring 2004 Pointers and linked lists  human chain analogy  linked lists: adding/deleting/traversing nodes  Node.
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
SNU IDB Lab. Ch7. Linear Lists – Simulated Pointers © copyright 2006 SNU IDB Lab.
Storage Management. The stack and the heap Dynamic storage allocation refers to allocating space for variables at run time Most modern languages support.
Lists II. List ADT When using an array-based implementation of the List ADT we encounter two problems; 1. Overflow 2. Wasted Space These limitations are.
Object-Oriented Programming in C++
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
1 Linked Structures, LinkedSet References as Links Linear Linked Lists and Non-linear Structures Managing Linked Lists Data Encapsulation Separate from.
COSC 1P03 Data Structures and Abstraction 5.1 Linear Linked Structures A bank is a place where they lend you an umbrella in fair weather and ask for it.
1 Today’s Material List ADT –Definition List ADT Implementation: LinkedList.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
List Interface and Linked List Mrs. Furman March 25, 2010.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Simulated Pointers Limitations Of C++ Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
1 Chapter 4 Unordered List. 2 Learning Objectives ● Describe the properties of an unordered list. ● Study sequential search and analyze its worst- case.
CHAPTER 51 LINKED LISTS. Introduction link list is a linear array collection of data elements called nodes, where the linear order is given by means of.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
Linked Lists A formal data structure. Linked Lists Collections of data items “lined up in a row” Inserts and deletes can be done anywhere in the list.
Runtime Environments Chapter 7. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Data Structures and Algorithm Analysis Dr. Ken Cosh Linked Lists.
CSE 220 – C Programming malloc, calloc, realloc.
Memory Management.
Garbage Collection What is garbage and how can we deal with it?
Storage 18-May-18.
Lectures linked lists Chapter 6 of textbook
The Class ArrayLinearList
UNIT-3 LINKED LIST.
Data Structures Interview / VIVA Questions and Answers
Concepts of programming languages
Pointers and Dynamic Variables
Simulated Pointers.
Simulated Pointers.
Iterators An iterator permits you to examine the elements of a data structure one at a time. C++ iterators Input iterator Output iterator Forward iterator.
Linked Representation
Iterators An iterator permits you to examine the elements of a data structure one at a time. C++ iterators Input iterator Output iterator Forward iterator.
Java Programming Language
Data Structures & Algorithms
Chapter 5 Linked Lists © 2011 Pearson Addison-Wesley. All rights reserved.
LINKED LIST Dr. T. Kokilavani Assistant Professor
Linked Lists list elements are stored, in memory, in an arbitrary order explicit information (called a link) is used to go from one element to the next.
Garbage Collection What is garbage and how can we deal with it?
Presentation transcript:

Simulated Pointers

Limitations Of Java Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization. No arithmetic.

Simulated-Pointer Memory Layout Data structure memory is an array, and each array position has an element field (type Object) and a next field (type int). caedb

Node Representation package dataStructures; class SimulatedNode { // package visible data members Object element; int next; // constructors not shown }

How It All Looks 14 caedb caedb firstNode = 4 next element

Still Drawn The Same abcde firstNode

Memory Management Linked system (Java or simulated pointer) requires: a way to keep track of the memory that is not in use (i.e., a storage pool) way to allocate a node Java has the method new way to free a node that is no longer in use Java uses garbage collection

Garbage Collection The system determines which nodes/memory are not in use and returns these nodes (this memory) to the pool of free storage. This is done in two or three steps: Mark nodes that are in use. Compact free space (optional). Move free nodes to storage pool.

Marking Unmark all nodes (set all mark bits to false). Start at each program variable that contains a reference, follow all pointers, mark nodes that are reached. caedb firstNode

Marking caedb firstNode caede Repeat for all reference variables. Start at firstNode and mark all nodes reachable from firstNode.

Compaction Move all marked nodes (i.e., nodes in use) to one end of memory, updating all pointers as necessary. cbedb firstNode aed Free Memory

Put Free Memory In Storage Pool Scan memory for unmarked nodes (if no compaction done), otherwise put single free block (unless no free memory) into pool.

Advantages Of Garbage Collection Programmer doesn’t have to worry about freeing nodes as they become free. However, for garbage collection to be effective, we must set reference variables to null when the object being referenced is no longer needed.

Advantages Of Garbage Collection Applications may run faster when run on computers that have more memory.

Disadvantage Of Garbage Collection Garbage collection time is linear in memory size (not in amount of free memory).

Alternative To Garbage Collection Provide a method to free/deallocate a node. e.g., delete method of C++ Now free nodes are always in storage pool.

Advantage Of Alternative Time to free nodes is proportional to number of nodes being freed and not to total memory size.

Disadvantages Of Alternative User must write methods to free data structure nodes. Time is spent freeing nodes that may not be reused. Application run time does not improve with increase in memory size.

Storage Pool Organization When All Nodes Have Same Size abcde null firstNode Maintain a chain of free nodes Allocate from front of chain Add node that is freed to chain front

Simulated-Pointer Memory Management /** memory management for simulated pointer classes */ package dataStructures; import utilities.*; public class SimulatedSpace1 { // data members private int firstNode; SimulatedNode [] node; // package visible // constructor and other methods come here }

Constructor public SimulatedSpace1(int numberOfNodes) { node = new SimulatedNode [numberOfNodes]; // create nodes and link into a chain for (int i = 0; i < numberOfNodes - 1; i++) node[i] = new SimulatedNode(i + 1); // last node of array and chain node[numberOfNodes - 1] = new SimulatedNode(-1); // firstNode has the default initial value 0 }

Allocate A Node public int allocateNode(Object element, int next) {// Allocate a free node and set its fields. if (firstNode == -1) { // double number of nodes, code omitted } int i = firstNode; // allocate first node firstNode = node[i].next; // firstNode points to next free node node[i].element = element; node[i].next = next; return i; }

Free A Node public void deallocateNode(int i) {// Free node i. // make i first node on free space list node[i].next = firstNode; firstNode = i; // remove element reference so that space can be garbage // collected node[i].element = null; }

Simulated Pointers Can allocate a chain of nodes without having to relink. Can free a chain of nodes in O(1) time when first and last nodes of chain are known.

Simulated Pointers Don’t use unless you see a clear advantage to using simulated pointers over Java references.