Dynamic Memory And Objects

Slides:



Advertisements
Similar presentations
Carnegie Mellon 1 Dynamic Memory Allocation: Basic Concepts : Introduction to Computer Systems 17 th Lecture, Oct. 21, 2010 Instructors: Randy Bryant.
Advertisements

Run-time Environment for a Program different logical parts of a program during execution stack – automatically allocated variables (local variables, subdivided.
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 Procedure Calls, Linking & Launching Applications Lecture 15 Digital Design and Computer Architecture Harris & Harris Morgan Kaufmann / Elsevier, 2007.
Analysis of programs with pointers. Simple example What are the dependences in this program? Problem: just looking at variable names will not give you.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
The University of Adelaide, School of Computer Science
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
COMP3221: Microprocessors and Embedded Systems Lecture 12: Functions I Lecturer: Hui Wu Session 2, 2005.
Dynamic Memory Allocation in C++. Memory Segments in C++ Memory is divided in certain segments – Code Segment Stores application code – Data Segment Holds.
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.
CS 536 Spring Run-time organization Lecture 19.
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.
C and Data Structures Baojian Hua
Run-time Environment and Program Organization
CS 140 Lecture Notes: Virtual MemorySlide 1 Load-Time Relocation Process 1 0 ∞ Process 3 Operating System Process 6.
Memory Layout C and Data Structures Baojian Hua
1 Memory Model of A Program, Methods Overview l Memory Model of JVM »Method Area »Heap »Stack.
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
Outline Midterm results Static variables Memory model
The Stack Pointer and the Frame Pointer (Lecture #19) ECE 445 – Computer Organization The slides included herein were taken from the materials accompanying.
Runtime Environments Compiler Construction Chapter 7.
ITEC 352 Lecture 18 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Exam –Average 76 Methods for functions in assembly.
Stack and Heap Memory Stack resident variables include:
1 Program Layout in memory –Code –Data Global variables –Stack Local variables & function Invocation Frames –Heap Dynamically allocated memory Today’s.
1 Writing a Good Program 8. Elementary Data Structure.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
Operating Systems Lesson 5. Plan Memory Management ◦ Memory segments types ◦ Processes & Memory ◦ Virtual Memory ◦ Virtual Memory Management ◦ Swap File.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
CS 140 Lecture Notes: Virtual MemorySlide 1 Load-Time Relocation Process 1 0 ∞ Process 3 Operating System Process 6.
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
CS 140 Lecture Notes: Virtual Memory
Pointers and dynamic memory
Lecture 4: MIPS Instruction Set
Run-time organization
Chien-Chung Shen CIS/UD
Dynamic Memory CSCE 121 J. Michael Moore.
Pointers and Dynamic Variables
Dynamically Allocated Memory
CS 140 Lecture Notes: Virtual Memory
System Structure and Process Model
Dynamic Memory A whole heap of fun….
Dynamic Memory Allocation
Understanding Program Address Space
CS 140 Lecture Notes: Virtual Memory
Pointers & Objects.
Pointers and dynamic memory
Dynamic Memory A whole heap of fun….
Binding Times Binding is an association between two things Examples:
Stack Frames and Functions
Dynamic Memory A whole heap of fun….
Linked List and Selection Sort
Program and memory layout
Destructor CSCE 121 J. Michael Moore.
Arrays an array of 5 ints is filled with 3,2,4,1,7
Destructor CSCE 121.
Dynamic Memory A whole heap of fun….
C H A P T E R F I V E Memory Management.
Linked List Functions.
Where is all the knowledge we lost with information? T. S. Eliot
CSE 153 Design of Operating Systems Winter 2019
Program and memory layout
CS 140 Lecture Notes: Virtual Memory
Dynamic Memory CSCE 121.
Run-time environments
SPL – PS2 C++ Memory Handling.
Presentation transcript:

Dynamic Memory And Objects

What will this do? What is the difference between these two samples?

The Stack Traditional model: Stack grows down in memory CODE GLOBALS

The Stack Traditional model: Stack grows down in memory Each function adds a Stack Frame : new set of local variables CODE GLOBALS STACK STACK FRAME

The Stack Traditional model: Stack grows down in memory Each function adds a Stack Frame : new set of local variables Exiting a function removes a stack frame CODE GLOBALS STACK STACK FRAME

The Heap Heap is memory managed by OS and programmer C++ program calls new to ask for heap space CODE GLOBALS STACK STACK FRAME HEAP Stays until explicitly freed

The Heap Heap is unaffected by changes to stack CODE GLOBALS STACK

The Heap Heap is unaffected by changes to stack CODE GLOBALS STACK HEAP Stays until explicitly freed

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 996 992 988 984 980

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 996 992 988 984 980

Guidance Can use pointer to object on either stack or heap For now You MUST use pointers for heap objects For now Put objects on stack