Program Compilation and Execution

Slides:



Advertisements
Similar presentations
Dynamic memory allocation
Advertisements

Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Run-time Environment for a Program different logical parts of a program during execution stack – automatically allocated variables (local variables, subdivided.
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
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.
DSP Implementation Lecture 3. Anatomy of a DSP Project In VDSP Linker Description File (.LDF) Source Files (.asm,.c,.h,.cpp,.dat) Object Files (.doj)
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:
Dynamic memory allocation. The process of allocating memory at run time is known as dynamic memory allocation. C have four library functions for allocating.
Cmput Lecture 8 Department of Computing Science University of Alberta ©Duane Szafron 2000 Revised 1/26/00 The Java Memory Model.
1 Day 03 Introduction to C. 2 Memory layout and addresses r s int x = 5, y = 10; float f = 12.5, g = 9.8; char c = ‘r’, d = ‘s’;
Dynamic Memory Allocation in C++. Memory Segments in C++ Memory is divided in certain segments – Code Segment Stores application code – Data Segment Holds.
Lifetime “The lifetime of a variable is the time during which the variable is bound to a specific memory location.” [p. 219] “…the lifetime of a variable.
Run-Time Storage Organization
C and Data Structures Baojian Hua
Run-time Environment and Program Organization
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.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
Dynamic Memory Allocation. One Dimensional Dynamic Memory #define SIZE1 25 #define SIZE2 36 int *p; long double *q; p = (int *)malloc(SIZE1 * sizeof(int));
1 CSCE3193: Programming Paradigms Nilanjan Banerjee Programming Paradigms University of Arkansas Fayetteville, AR
CS3012: Formal Languages and Compilers The Runtime Environment After the analysis phases are complete, the compiler must generate executable code. The.
Programming Intro Problem Solving: 1)Understand the problem This often involves breaking the problem into manageable pieces 2) Develop a plan May develop.
Outline Midterm results Static variables Memory model
Runtime Environments Compiler Construction Chapter 7.
Program Compilation and Execution. Today’s Objectives Explain why runtime stack needed for C Explain why runtime stack needed for C Draw logical division.
Dynamic Memory Allocation The process of allocating memory at run time is known as dynamic memory allocation. C does not Inherently have this facility,
Storage Bindings Allocation is the process by which the memory cell or collection of memory cells is assigned to a variable. These cells are taken from.
1 Program Layout in memory –Code –Data Global variables –Stack Local variables & function Invocation Frames –Heap Dynamically allocated memory Today’s.
Chapter 14 Memory API Chien-Chung Shen CIS, UD
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
ECE 103 Engineering Programming Chapter 36 C Storage Classes Herbert G. Mayer, PSU CS Status 8/4/2014 Initial content copied verbatim from ECE 103 material.
+ Dynamic memory allocation. + Introduction We often face situations in programming where the data is dynamics in nature. Consider a list of customers.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Multi-dimensional Arrays and other Array Oddities Rudra Dutta CSC Spring 2007, Section 001.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
Int main( ) { x = a(); } int a() { y = b(); } int b() { z = c(); } int c() { } 1.
CSE 333 – SECTION 2 Memory Management. Questions, Comments, Concerns Do you have any? Exercises going ok? Lectures make sense? Homework 1 – START EARLY!
“Success consists of going from failure to failure without loss of enthusiasm.” Winston Churchill.
Variables Bryce Boe 2012/09/05 CS32, Summer 2012 B.
Memory allocation & parameter passing
Java Memory Management
Java Memory Management
Day 03 Introduction to C.
ENERGY 211 / CME 211 Lecture 25 November 17, 2008.
Pointers and dynamic memory
Lecture 4: MIPS Instruction Set
Day 03 Introduction to C.
CSC 253 Lecture 8.
Today’s Topic Breakdown of CC script.
CSC 253 Lecture 8.
Activation Records and Function Calls
Computer Organization & Compilation Process
understanding memory usage by a c++ program
More examples How many processes does this piece of code create?
Dynamic Memory Allocation
Memory Allocation CS 217.
Understanding Program Address Space
Pointers and dynamic memory
Dynamic Memory A whole heap of fun….
Binding Times Binding is an association between two things Examples:
C (and C++) Pointers April 4, 2019.
Dynamic Memory A whole heap of fun….
C Programming Pointers
Address Spaces Physical Memory Virtual Memory Process Memory Layout
Computer Organization & Compilation Process
RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science
How Memory Leaks Work with Memory Diagram
Run-time environments
Runtime Stack Activation record for hanoi;
Presentation transcript:

Program Compilation and Execution

Today’s Objectives Explain why runtime stack needed for C Draw logical division of memory into stack, heap Compare and contrast stack and heap List variables stored in heap; stack; neither

Logical Memory Layout Stack Heap Static Space D Y N A M I C Currently not in use Currently not in use Heap Static Space

Dice.c int NUM = 100000; main() { int i, roll, *counts; counts = (int *) malloc (13 * sizeof(int)); for (i = 0; i < 13; i++) counts[i] = 0; for ( i = 0; i < NUM; i++) roll = rand() % 6 + rand() %6 + 2 counts[roll]++; for (i = 2; i < 13; i++) printf(“There were %d rolls of %d\n”, counts[i],i); }

Where Are the Variables? Stack D Y N A M I C i; roll; counts Currently not in use Currently not in use Space for 13 ints – pointed to by counts Heap Num “There were %d rolls of %d\n” Static Space

Runtime Stack Activation record for Hanoi; 1 2 3 1 Activation Record for Main Activation record for main