Lecture 4: Process Memory Layout

Slides:



Advertisements
Similar presentations
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.
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.
Algorithms and data structures
Carnegie Mellon 1 Dynamic Memory Allocation: Basic Concepts : Introduction to Computer Systems 17 th Lecture, Oct. 21, 2010 Instructors: Randy Bryant.
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.
Chris Riesbeck, Fall 2007 Dynamic Memory Allocation Today Dynamic memory allocation – mechanisms & policies Memory bugs.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
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.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
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’;
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.
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
Run-Time Storage Organization
Pointers. 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.
C and Data Structures Baojian Hua
1 CSE 303 Lecture 11 Heap memory allocation ( malloc, free ) reading: Programming in C Ch. 11, 17 slides created by Marty Stepp
Memory Layout C and Data Structures Baojian Hua
Tutorial 6 Memory Management
CS 403: Programming Languages Lecture 2 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
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.
1 Program Layout in memory –Code –Data Global variables –Stack Local variables & function Invocation Frames –Heap Dynamically allocated memory Today’s.
Basic Semantics Associating meaning with language entities.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R F I V E Memory Management.
Dynamic Memory Allocation. Domain A subset of the total domain name space. A domain represents a level of the hierarchy in the Domain Name Space, and.
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.
COMP3190: Principle of Programming Languages
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
RUNTIME ENVIRONMENT AND VARIABLE BINDINGS How to manage local variables.
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.
Design issues for Object-Oriented Languages
Dynamic Allocation in C
Storage Allocation Mechanisms
Names and Attributes Names are a key programming language feature
Day 03 Introduction to C.
CS 326 Programming Languages, Concepts and Implementation
ENERGY 211 / CME 211 Lecture 25 November 17, 2008.
Pointers and dynamic memory
Dynamic Memory Allocation
Procedures (Functions)
Day 03 Introduction to C.
Checking Memory Management
Dynamically Allocated Memory
Lecture 5: Process Creation
More examples How many processes does this piece of code create?
Lecture 7: Introduction to Threads
Dynamic Memory A whole heap of fun….
Dynamic Memory Allocation
Memory Allocation CS 217.
Understanding Program Address Space
Pointers and dynamic memory
System Calls David Ferry CSCI 3500 – Operating Systems
Lecture 6: Multiprogramming and Context Switching
Lecture 7: Introduction to Threads
Dynamic Memory.
CS703 - Advanced Operating Systems
Dynamic Memory CSCE 121.
Pointers, Dynamic Data, and Reference Types
Classes and Objects Object Creation
Run-time environments
Topic 2b ISA Support for High-Level Languages
CSE 303 Concepts and Tools for Software Development
CMSC 202 Constructors Version 9/10.
Dynamic Data Structures
Presentation transcript:

Lecture 4: Process Memory Layout

Review: Unix File Access Control Subject Users(owner, group, others) Object Directory/File Actions read write execute Each file has associated with it a set of access permissions indicating, for each of three classes of principals, what sorts of operations on the file are allowed. The three classes are the owner of the file, known as user, the group owner of the file, known simply as group, and everyone else, known as others. The operations are grouped into the classes read, write, and execute, with their obvious meanings. The access permissions apply to directories as well as to ordinary files, though the meaning of execute for directories is not quite so obvious: one must have execute permission for a directory file in order to follow a path through it. The system, when checking permissions, first determines the smallest class of principals the requester belongs to: user (smallest), group, or others (largest). It then, within the chosen class, checks for appropriate permissions. Copyright © 2002 Thomas W. Doeppner. All rights reserved.

System Calls For File Management

System Calls For Directory Management

System Calls For Miscellaneous Tasks

In this lecture Process memory layout

Linux process memory layout Stack Heap Static data Text (program) Address space or core image

Linux process memory layout Stack: Automatically allocated and deallocated Local variables, parameters Heap: Manually allocated (malloc) and deallocated (free) Dynamic sized data structures Static data Global variables Text Program

An example int g; int main() { int a; int*b = (int*)malloc(sizeof(int) *2); return 0; }

An example Stack, a Stack, b Heap, b_content Static data, g Text (program)

Multiple processes in memory Unused Stack Heap Static data Text (program) Process 1 Stack Heap Static data Text (program) Unused Process 2

Function Call int main() { int a; a=f(); } int f() { int a,b; return (a*b); }

Stack Frame arguments return address stack frame pointer Heap Static data Text (program) arguments return address stack frame pointer local variables To previous stack frame pointer To the point at which this function was called

Function Call Hierarchy int f() { int a; a=10; return (a*g()); } int g() { int a; a=100; return (a); } int main() { int a; a=f(); }

Fibonacci Numbers int fib (int n) { if (n < 0) return 0; return (fib(n-1)+fib(n-2)); } fib (3): how many stack frames?

Memory leakage Stack, a Stack, b (pointer) Heap, b_content Static data, g Text (program)

Garbage Collection No need to explicitly deallocate memory i.e. no need for free() or equivalent No memory leaks Automatic Garbage Collection http://sleibowitz.home.att.net/CPP_Java/AGC.html A key feature of Java is its garbage-collected heap http://www.javaworld.com/javaworld/jw-08-1996/jw-08-gc.html

Summarizing Process memory layout Stack frame for function calls Stack Heap Static data Text Stack frame for function calls