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.

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

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.
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
A pointer is the memory address of a variable. A memory address is a physical location within a system’s memory space. A pointer variable is variable used.
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
David Notkin Autumn 2009 CSE303 Lecture 13 This space for rent.
Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
CS-1030 Dr. Mark L. Hornick 1 Pointers And Dynamic Memory.
Memory allocation CSE 2451 Matt Boggus. sizeof The sizeof unary operator will return the number of bytes reserved for a variable or data type. Determine:
Informática II Prof. Dr. Gustavo Patiño MJ
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
Dynamic Memory Allocation in C++. Memory Segments in C++ Memory is divided in certain segments – Code Segment Stores application code – Data Segment Holds.
Objectives Learn about objects and reference variables Explore how to use predefined methods in a program.
Run-Time Storage Organization
Pointers and Dynamic Variables. Objectives on completion of this topic, students should be able to: Correctly allocate data dynamically * Use the new.
1 ES 314 Advanced Programming Lec 3 Sept 8 Goals: complete discussion of pointers discuss 1-d array examples Selection sorting Insertion sorting 2-d arrays.
Memory and C++ Pointers.  C++ objects and memory  C++ primitive types and memory  Note: “primitive types” = int, long, float, double, char, … January.
1 CSE 303 Lecture 11 Heap memory allocation ( malloc, free ) reading: Programming in C Ch. 11, 17 slides created by Marty Stepp
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
Garbage Collection CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
11 Values and References Chapter Objectives You will be able to: Describe and compare value types and reference types. Write programs that use variables.
EE4E. C++ Programming Lecture 1 From C to C++. Contents Introduction Introduction Variables Variables Pointers and references Pointers and references.
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. This is.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
This set of notes is adapted from that provided by “Computer Science – A Structured Programming Approach Using C++”, B.A. Forouzan & R.F. Gilberg, Thomson.
Advanced Java Programming CS 537 – Data Structures and Algorithms.
Chapter 9 Pointers and Dynamic Arrays (9.1). Pointers A variables which holds the memory address for a variable of a specific type. Call-by-Reference.
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++
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
Chapter 7 Pointers: Java does not have pointers. Used for dynamic memory allocation.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
P OINTERS A pointer is an address All data is stored in memory in some location that is indexed with an address Can refer to variables by name or by memory.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
Sections Basic Data Structures. 1.5 Data Structures The way you view and structure the data that your programs manipulate greatly influences your.
POINTERS AND MEMORY ACKNOWLEDGEMENT: THE SLIDES ARE PREPARED FROM SLIDES PROVIDED BY NANCY M. AMATO AND JORY DENNY 1.
Objects and Memory Mehdi Einali Advanced Programming in Java 1.
C11, Implications of Inheritance
Computer Organization and Design Pointers, Arrays and Strings in C
Unit-2 Objects and Classes
Dynamic Memory CSCE 121 J. Michael Moore.
Dynamically Allocated Memory
Lecture 4: Process Memory Layout
Pointers, Dynamic Data, and Reference Types
Dynamic Memory A whole heap of fun….
Dynamic Memory Allocation
Pointers And Memory Acknowledgement: THE Slides are Prepared FROM SLIDES PROVIDED By NANCY M. AMATO AND Jory Denny.
Indirection.
Dynamic Memory A whole heap of fun….
Dynamic Memory A whole heap of fun….
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.
Dynamic Memory A whole heap of fun….
Dynamic Memory.
C Programming Pointers
Dynamic Memory And Objects
The Stack.
Chapter 5 Linked Lists © 2011 Pearson Addison-Wesley. All rights reserved.
Pointers and References
Dynamic Memory CSCE 121.
Pointers, Dynamic Data, and Reference Types
Classes and Objects Object Creation
Run-time environments
SPL – PS2 C++ Memory Handling.
CMSC 202 Constructors Version 9/10.
Presentation transcript:

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 for a pointer to an int Pointer and pointee are different –Space for pointee must be allocated before pointer dereferencing is sensible Assignment to a pointer copies address, not contents

CSE 2502 Where am I? The & operator yields the address of a variable Examples: int x = 12; int * px; px = &x; // assigns to px the address of x

CSE 2503 “Clean up after yourself!” C++ does not have automatic garbage collection like Java does It is the programmer’s responsibility to return to free space any memory reserved using the new operator. Memory allocated using new must be freed using delete.

CSE 2504 delete operator int * px; px = new int(3); … do some work until finished with the space px points to… delete px;

CSE 2505 Memory areas memory allocated to other process static allocation stack (grows down) (unused memory) heap (grows up) memory allocated to other process

CSE 2506 Classes Syntax to define classes in C++ is similar but not identical to that in Java. The class is declared independently of its implementation.

CSE 2507 Class declaration class Point { public: Point(int,int); int getX(); int getY(); void setX(int); void setY(int); private: int x, y; };