Pointers & Objects.

Slides:



Advertisements
Similar presentations
A method for addressing any large problem. Carefully consider the problem. Define the problem. Ask yourself the following questions: What is it that I.
Advertisements

Pointer Variables The normal variables hold values. For example, int j; j = 2; Then a reference to j in an expression will be identified with the value.
Data Structures (Second Part) Lecture 2 : Pointers Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
Dynamic Allocation Eric Roberts CS 106B February 4, 2013.
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.
Pointers and Dynamic Memory Allocation. Dynamic Data Suppose we write a program to keep track of a list of students How many student records should we.
Pointers Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences National Cheng.
Basic Computer Organization Background for CS260.
Programming Pointers. COMP104 Lecture 32 / Slide 2 Pointers l Pointers are objects whose values are the locations of other objects l Pointers are memory.
Welcome to CISC220 Data Structures in C++ sakai.udel.edu Office Hours: Mon / Wed 2:30PM - 4PM TAs: Miao Tang,
1 Memory Model of A Program, Methods Overview l Memory Model of JVM »Method Area »Heap »Stack.
ITEC 352 Lecture 18 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Exam –Average 76 Methods for functions in assembly.
C++ Data Types Structured array struct union class Address pointer reference Simple IntegralFloating char short int long enum float double long double.
C++ REVIEW – POINTERS AND TEST DRIVEN DEVELOPMENT.
Tracing through E01, question 9 – step 1 // p02.cc P. Conrad, for CISC181 07S // Exam question for E01 #include using namespace std; void mysteryFunction(int.
Chapter 13: Structures. In this chapter you will learn about: – Single structures – Arrays of structures – Structures as function arguments – Linked lists.
Welcome to CISC220H Data Structures in C++ sakai.udel.edu Office Hours: Mon/Wed 3:30PM - 4:30PM TA: Adnan Ozsoy.
1. Circular Linked List In a circular linked list, the last node contains a pointer to the first node of the list. In a circular linked list,
Pointers & Objects & Aggregation Who's your daddy?
Administering a heap of H bytes Address = 0Address = H - 1 Free List Pointer :
Smart Pointers. Dumb Pointers Pointers Necessary – Dynamic memory – Sharing memory.
Welcome to CISC220 Data Structures in C++ sakai.udel.edu Office Hours: Tues 3PM - 4PM / Thurs 1PM - 2PM TA: David.
Announcements There is a Quiz today. There were problems with grading assignment 2, but they should be worked out today The web page for correcting the.
 Memory from the heap  Dynamic memory allocation using the new operator  Build a dynamic linked list  Another way of traversing a linked list 
This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5 License. All rights reserved.
CS162 - Topic #6 Lecture: Pointers and Dynamic Memory –Review –Dynamically allocating structures –Combining the notion of classes and pointers –Destructors.
Container Classes. How do we do better? Tough to delete correctly: startLocation.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Reminders: Have you filled out the questionnaire in Moodle? (3 left – as of last night). Office hours.
C Lab 2 Intermediate Pointers & Basic Structures.
ПЕЧЕНЬ 9. Закладка печени в период эмбрионального развития.
CS 140 Lecture Notes: Virtual Memory
ENERGY 211 / CME 211 Lecture 25 November 17, 2008.
Pointers Revisited What is variable address, name, value?
CSCI206 - Computer Organization & Programming
Dynamic Memory CSCE 121 J. Michael Moore.
Clear1 and Clear2 clear1(int array[], int size) { int i; for (i = 0; i < size; i += 1) array[i] = 0; } clear2(int *array, int size) {
Pointers and References
Dynamic Memory Allocation
CSC 253 Lecture 8.
CS 140 Lecture Notes: Virtual Memory
CSC 253 Lecture 8.
Smart Pointers.
Dynamic Memory A whole heap of fun….
Dynamic Memory Copy Challenge
CS 140 Lecture Notes: Virtual Memory
Memory Physical and Virtual
8085 MICROPROCESSOR 8085 CPU Registers and Status Flags S Z AC P C A B
Dynamic Memory A whole heap of fun….
How Dynamic Memory Works with Memory Diagram
Dynamic Memory A whole heap of fun….
Destructor CSCE 121 J. Michael Moore.
Class and Objects In a class, all the functions that operate on the data structure are grouped together in one place along with the data Like a struct.
Destructor CSCE 121.
Dynamic Memory A whole heap of fun….
Dynamic Memory And Objects
Address Spaces Physical Memory Virtual Memory Process Memory Layout
Dynamic Memory Copy Challenge
The Stack.
Linked List Functions.
Linked Lists.
Traversing a Linked List
Pointers and References
CS 140 Lecture Notes: Virtual Memory
How Dynamic Memory Works with Memory Diagram
Dynamic Memory CSCE 121.
How Memory Leaks Work with Memory Diagram
Automating Memory Management
Run-time environments
Presentation transcript:

Pointers & Objects

Objects on Stack Objects created without new are on the stack: 2000 p1 Address Identifier Value 2000 p1 Point 1996 1992 1988 1984 1980 1976 … 1000 999 998 997 996 995

Objects on Heap Objects created with new are on heap Use pointer to keep track of Address Identifier Value 2000 pp 1000 1996 1992 1988 1984 1980 1976 … Point 999 998 997 996 995

Objects on Heap Objects can be on the heap: But member access is tricky

Pointer Member Access Precedence : * comes after . *pp.getX() == *(pp.getX()) Ask memory address to getX??? Address Identifier Value 2000 pp 1000 1996 1992 1988 1984 1980 1976 … Point 999 998 997 996 995

Pointer Member Access Precedence corrected with ( ) Go to point pp points to, ask it to getX() Address Identifier Value 2000 pp 1000 1996 1992 1988 1984 1980 1976 … Point 999 998 997 996 995

Pointer Member Access (*pointer).member Gets ugly

Pointer Member Access (*pointer).member -> : pointer member access Gets ugly -> : pointer member access Dereference pointer, access member in one

Pointer Member Access -> : pointer member access Much better for: Dereference pointer, access member in one Much better for: