C++ Interlude 2 Pointers, Polymorphism, and Memory Allocation

Slides:



Advertisements
Similar presentations
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
Advertisements

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.
1 Pointers (Walls & Mirrors - Beginning of Chapter 4)
Dynamic Objects. COMP104 Lecture 31 / Slide 2 Static verses Dynamic Objects * Static object n Memory is acquired automatically  int A[10]; n Memory is.
C++ Interlude 2 Pointers, Polymorphism, and Memory Allocation
Dynamic Memory Allocation. One Dimensional Dynamic Memory #define SIZE1 25 #define SIZE2 36 int *p; long double *q; p = (int *)malloc(SIZE1 * sizeof(int));
February 11, 2005 More Pointers Dynamic Memory Allocation.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Dynamic Memory Allocation 9.8.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
7. Pointers, Dynamic Memory 20 th September IIT Kanpur 1C Course, Programming club, Fall 2008.
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.
Dynamic Memory Allocation The process of allocating memory at run time is known as dynamic memory allocation. C does not Inherently have this facility,
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
1 Dynamic Memory Allocation –The need –malloc/free –Memory Leaks –Dangling Pointers and Garbage Collection Today’s Material.
Revision on C++ Pointers TCP1201: 2013/2014. Pointer Basics  Why pointer is important? 1. Reference/Point to existing data without cloning the data.
POINTERS IN C. Introduction  A pointer is a variable that holds a memory address  This address is the location of another object (typically another.
Scis.regis.edu ● CS-362: Data Structures Week 6 Part 2 Dr. Jesús Borrego 1.
Presented by Ted Higgins, SQL Server DBA C Programming - Pointers.
UNIT 8 Pointers.
Memory allocation & parameter passing
CS1010 Programming Methodology
CS1010 Programming Methodology
Day 03 Introduction to C.
Computer Science 210 Computer Organization
Lesson One – Creating a thread
Introduction to Programming
ENEE150 Discussion 07 Section 0101 Adam Wang.
Midterm review October 02, 2017 Geoffrey Tien.
Pointers, Polymorphism, and Memory Allocation
Dynamic Array Multidimensional Array Matric Operation with Array
Making Dynamic Memory Allocation Safer
Day 03 Introduction to C.
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
CSCI206 - Computer Organization & Programming
Dynamic Memory CSCE 121 J. Michael Moore.
Dynamic Memory Allocation
14th September IIT Kanpur
CSC 253 Lecture 8.
CSC 253 Lecture 8.
Memory Segments Code (.code) Data (.data) Stack Heap
Computer Science 210 Computer Organization
Dynamic Memory A whole heap of fun….
Memory Allocation CS 217.
Pointers And Memory Acknowledgement: THE Slides are Prepared FROM SLIDES PROVIDED By NANCY M. AMATO AND Jory Denny.
Pointers and Dynamic Variables
Chapter 17: Linked Lists.
2 code samples int [] array; int i, j, temp; for(i = 0; i < array.length/2; i++) { j = array.length-1-i; temp = array[i]; array[i] = array[j]; array[j]
EENG212 – Algorithms & Data Structures Fall 07/08 – Lecture Notes # 5b
Memory Leaks and Dangling Pointers
Jeff West - Quiz Section 8
7. Pointers, Dynamic Memory
Dynamic Memory A whole heap of fun….
Dynamic Memory.
C Programming Lecture-8 Pointers and Memory Management
C Programming Pointers
Chapter 9: Pointers and String
C H A P T E R F I V E Memory Management.
Dynamic Memory Allocation
RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science
ENERGY 211 / CME 211 Lecture 10 October 13, 2008.
Session #6 Memory Allocation and leaks Structures
Dynamic Memory CSCE 121.
How Memory Leaks Work with Memory Diagram
Run-time environments
Pointers.
SPL – PS2 C++ Memory Handling.
Arrays and Pointers.
Introduction to Pointers
Lecture 4 – Data collection List ADT
Presentation transcript:

C++ Interlude 2 Pointers, Polymorphism, and Memory Allocation CS 302 Data Structures C++ Interlude 2 Pointers, Polymorphism, and Memory Allocation

Review What is a template? How do we declare one? How do we use one?

Memory Allocation int a; int * a_ptr; Where is a? int * a_ptr; Allocate memory and have a_ptr point to it. Where is that memory?

Figure C2-2 Sample program memory layout

Figure C2-3 Run-time stack and free store.

Memory Allocation What is a memory leak? How do you create one? How do you de-allocate memory? What is a dangling pointer? Please declare an array of integers. Please declare a dynamically allocated array of integers.

End of C++ Interlude 2