Storage allocation issues Prof. Ramin Zabih

Slides:



Advertisements
Similar presentations
Data Structures Static and Dynamic.
Advertisements

Dynamic Memory Management
Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Understanding Operating Systems Fifth Edition
PZ10B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10B - Garbage collection Programming Language Design.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Memory allocation in computer science, is the act of allocating memory to a program for its usage, typically for storing variables, code or data. Memory.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
CS 1114: Data Structures – memory allocation Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
CS 1114: Data Structures – Implementation: part 1 Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
CS 61C L07 More Memory Management (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
Linked lists Prof. Noah Snavely CS1114
Pointers and Dynamic Variables. Objectives on completion of this topic, students should be able to: Correctly allocate data dynamically * Use the new.
Garbage collection (& Midterm Topics) David Walker COS 320.
Linked lists and memory allocation Prof. Noah Snavely CS1114
1 Dynamic Memory Management. 2 What’s worse?  50% of instructions/data are cache misses (fetched from RAM)  1% of instructions/data are page faults.
CS61C L07 More Memory Management (1) Garcia, Spring 2008 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
Interpolation, extrapolation, etc. Prof. Ramin Zabih
COP4020 Programming Languages
CS 403: Programming Languages Lecture 2 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
CNIT 133 Interactive Web Pags – JavaScript and AJAX Advanced topic - variable.
Chapter 2 Memory Management: Early Systems Understanding Operating Systems, Fourth Edition.
Chapter 2 Memory Management: Early Systems Understanding Operating Systems, Fourth Edition.
Storage Management. The stack and the heap Dynamic storage allocation refers to allocating space for variables at run time Most modern languages support.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 15: More-Advanced Concepts.
Simulated Pointers Limitations Of Java Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
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.
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.
ECE 103 Engineering Programming Chapter 47 Dynamic Memory Alocation Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103.
1 Dynamic Memory Allocation –The need –malloc/free –Memory Leaks –Dangling Pointers and Garbage Collection Today’s Material.
Memory Management COSC 513 Presentation Jun Tian 08/17/2000.
Memory Management. Memory  Commemoration or Remembrance.
Finding Red Pixels Prof. Ramin Zabih
Heap storage & Garbage collection Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001.
Copyright © Genetic Computer School 2008 Computer Systems Architecture SA 7- 0 Lesson 7 Memory Management.
GARBAGE COLLECTION IN AN UNCOOPERATIVE ENVIRONMENT Hans-Juergen Boehm Computer Science Dept. Rice University, Houston Mark Wieser Xerox Corporation, Palo.
Memory Management -Memory allocation -Garbage collection.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 10 – C: the heap and manual memory management.
CS 241 Discussion Section (2/9/2012). MP2 continued Implement malloc, free, calloc and realloc Reuse free memory – Sequential fit – Segregated fit.
Simulated Pointers Limitations Of C++ Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
CS 241 Discussion Section (12/1/2011). Tradeoffs When do you: – Expand Increase total memory usage – Split Make smaller chunks (avoid internal fragmentation)
MEMORY MANAGEMENT Operating System. Memory Management Memory management is how the OS makes best use of the memory available to it Remember that the OS.
CS61C L07 More Memory Management (1) Garcia, Spring 2010 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
CS412/413 Introduction to Compilers and Translators April 21, 1999 Lecture 30: Garbage collection.
Implementing stacks Prof. Ramin Zabih
CSE 220 – C Programming malloc, calloc, realloc.
Storage 18-May-18.
Prof. Ramin Zabih Implementing queues Prof. Ramin Zabih
CSE 374 Programming Concepts & Tools
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 – More Memory Management Lecturer PSOE Dan Garcia
Storage Management.
Garbage collection; lightstick orientation
CMSC 341 Prof. Michael Neary
Simulated Pointers.
Simulated Pointers.
Prof. Ramin Zabih Least squares fitting Prof. Ramin Zabih
Preprocessing to accelerate 1-NN
Dynamic Memory Management
Dynamic Memory.
Heap storage & Garbage collection
Presentation made by Steponas Šipaila
Lecturer PSOE Dan Garcia
Linked lists Prof. Noah Snavely CS1114
Heap storage & Garbage collection
Comp 208 Computers in Engineering Yi Lin Fall, 2005
Garbage collection Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Dynamic Memory Management
Inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 – More Memory Management Lecturer PSOE Dan Garcia
Memory Management Memory management is the art and the process of coordinating and controlling the use of memory in a computer system Why memory management?
Presentation transcript:

Storage allocation issues Prof. Ramin Zabih

2 Administrivia  Assignment 3 is out, due Friday  Prelim on 10/11 –Quiz 4 this Tuesday, 10/2  Wednesday section will be led by RDZ –Topic: prelim review  Wednesday evening 10/3, RPC205: –7PM: Bobby Kleinberg on graphs (optional!)  Gurmeet will do additional review in section 10/10

3 Memory allocation  So far we just assumed that the hardware supplied us with a huge array M –When we need more storage, we just grab locations at the end Keep track of next free memory location –What can go wrong? Consider repeatedly adding, deleting an item  Notice that when we delete items from a linked list we simply changed pointers so that the items were inaccessible –But, they still waste space!

4 Storage reclamation  Someone has to figure out that certain locations can be re-used (“garbage”) –If this is too conservative, your program will run slower and slower (“memory leak”) –If it’s too aggressive, your program will crash (“blue screen of death”)  Suppose your linked list was corrupted  Why do computers crash when we read/write an arbitrary location? Must they??

5 Two basic options  Computer keeps track of free storage  Manual storage reclamation –Programmer has to explicitly free storage –Languages: C, C++, assembler  Automatic storage reclamation –Computer will free storage for you –Languages: Matlab, Java, C#, Scheme, SML  Basic tradeoff is program speed versus programmer effort –The computer isn’t as smart as a programmer

6 Allocation issues  Computer keeps a linked list of free storage blocks (“freelist”) –For each block, keep size and location –When asked for new storage, get from freelist  Surprisingly important question: –Which block do you supply?  Different sized blocks –Actually, several different lists (for efficiency) “Buddy block” system, see CS316/CS414 or

7 Manual storage reclamation  Programmers always ask for a block of memory of a certain size –In C, explicitly declare when it is free  Desirable but complex invariants: –Everything should be freed when it is no longer going to be used –And, it should be freed exactly once! –Also want to minimize fragmentation  Any serious C programmer writes their own memory allocation system!