Memory Management CSCI 2720 Spring 2005. What is memory management? “the prudent utilization of this scarce resource (memory), whether by conservation,

Slides:



Advertisements
Similar presentations
Garbage collection David Walker CS 320. Where are we? Last time: A survey of common garbage collection techniques –Manual memory management –Reference.
Advertisements

Dynamic Memory Management
Introduction to Memory Management. 2 General Structure of Run-Time Memory.
(Chapter 5) Deleting Objects
Chapter 2: Memory Management, Early Systems
Chapter 2: Memory Management, Early Systems
Memory Management, Early Systems
Garbage Collection CS Introduction to Operating Systems.
CMSC 330: Organization of Programming Languages Memory and Garbage Collection.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Free Space and Allocation Issues
Garbage Collection  records not reachable  reclaim to allow reuse  performed by runtime system (support programs linked with the compiled code) (support.
Compiler construction in4020 – lecture 12 Koen Langendoen Delft University of Technology The Netherlands.
5. Memory Management From: Chapter 5, Modern Compiler Design, by Dick Grunt et al.
Run-time organization  Data representation  Storage organization: –stack –heap –garbage collection Programming Languages 3 © 2012 David A Watt,
Garbage Collection CSCI 2720 Spring Static vs. Dynamic Allocation Early versions of Fortran –All memory was static C –Mix of static and dynamic.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
CPSC 388 – Compiler Design and Construction
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
Memory Management. History Run-time management of dynamic memory is a necessary activity for modern programming languages Lisp of the 1960’s was one of.
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)
Memory Management Professor Yihjia Tsai Tamkang University.
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
1 Storage Allocation Operating System Hebrew University Spring 2007.
CS 333 Introduction to Operating Systems Class 18 - File System Performance Jonathan Walpole Computer Science Portland State University.
Memory Management A memory manager should take care of allocating memory when needed by programs release memory that is no longer used to the heap. Memory.
Run time vs. Compile time
Memory Allocation and Garbage Collection. Why Dynamic Memory? We cannot know memory requirements in advance when the program is written. We cannot know.
Thrashing and Memory Management
Linked lists and memory allocation Prof. Noah Snavely CS1114
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Reference Counters Associate a counter with each heap item Whenever a heap item is created, such as by a new or malloc instruction, initialize the counter.
1 Memory Management in Representative Operating Systems.
SEG Advanced Software Design and Reengineering TOPIC L Garbage Collection Algorithms.
Dynamic Memory Allocation Questions answered in this lecture: When is a stack appropriate? When is a heap? What are best-fit, first-fit, worst-fit, and.
A Real-Time Garbage Collector Based on the Lifetimes of Objects Henry Lieberman and Carl Hewitt (CACM, June 1983) Rudy Kaplan Depena CS395T: Memory Management.
Compiler Construction
Chapter 4 Memory Management.
Storage Management. The stack and the heap Dynamic storage allocation refers to allocating space for variables at run time Most modern languages support.
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.
11/26/2015IT 3271 Memory Management (Ch 14) n Dynamic memory allocation Language systems provide an important hidden player: Runtime memory manager – Activation.
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
1 Languages and Compilers (SProg og Oversættere) Heap allocation and Garbage Collection.
ISBN Chapter 6 Data Types Pointer Types Reference Types Memory Management.
CS333 Intro to Operating Systems Jonathan Walpole.
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.
Consider Starting with 160 k of memory do: Starting with 160 k of memory do: Allocate p1 (50 k) Allocate p1 (50 k) Allocate p2 (30 k) Allocate p2 (30 k)
CS 241 Discussion Section (12/1/2011). Tradeoffs When do you: – Expand Increase total memory usage – Split Make smaller chunks (avoid internal fragmentation)
Dynamic Memory Management Jennifer Rexford 1. 2 Goals of this Lecture Dynamic memory management techniques Garbage collection by the run-time system (Java)
Chapter - 2 Data strucuters for Language processing.
Data Types Chapter 6: Data Types Lectures # 13. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.
Memory Management What if pgm mem > main mem ?. Memory Management What if pgm mem > main mem ? Overlays – program controlled.
CSC 533: Programming Languages Spring 2016
Storage Allocation Mechanisms
Jonathan Walpole Computer Science Portland State University
CSC 533: Programming Languages Spring 2015
Storage 18-May-18.
Dynamic Memory Allocation
Storage Management.
CS 153: Concepts of Compiler Design November 28 Class Meeting
Concepts of programming languages
Chapter 12 Memory Management
List Allocation and Garbage Collection
CS703 - Advanced Operating Systems
RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science
Automating Memory Management
CSC 533: Programming Languages Spring 2019
CMPE 152: Compiler Design May 2 Class Meeting
Presentation transcript:

Memory Management CSCI 2720 Spring 2005

What is memory management? “the prudent utilization of this scarce resource (memory), whether by conservation, recycling, or other strategies.”

Terminology heap** - a table M[0..N-1] of N cells Smaller blocks of memory are allocated from this heap An allocated block is said to be reserved or in use The allocated block may later be freed or deallocated. ** -- no relation to the partially ordered, implicitly represented tree we just talked about in class.

What’s a good MM scheme? It depends: Blocks of fixed size v. varying size Linked blocks v. unlinked blocks Small blocks v. large blocks Time v. memory Explicit v. implicit release Scheduled v. unscheduled release Initialized v. uninitialized blocks

Fixed v. varying size blocks If fixed, or large number of same size, makes sense to set aside a heap for those requests Fixed-size easier to manage

Linked v. unlinked If linked then can’t arbitrarily move blocks: Example: Can’t relocate B without breaking A A B

If unlinked, then Program A Program B Program C Program A Program B Program C Program D

Small v. large May need to handle a few bytes … or megabytes Small blocks – May make sense to move, zero out, etc. Large blocks Want to avoid operations whose performance depends on size of block

Time v. memory Which are you optimizing? If you can “waste” some memory (have a large heap), then may be able to use faster management algorithms. If memory is scarce, may need more time- consuming algorithms.

Explicit v. implicit release Does “user” notify memory manager when memory is no longer needed by program? Garbage = memory that MM has allocated, but that is no longer referenced by any variable that can/will be accessed by client. When can MM reclaim memory?

Scheduled v. unscheduled release Memory manager can benefit from knowing order in which memory will be released. (For example: if release is LIFO, can use a stack.)

Initialized v. uninitialized blocks Initialize to all zeros to meet semantics of programming language. Initialize for security purposes. … but takes time proportional to size of block.

Records of a single size Given heap of memory M[0..N-1], if records are all of same size k, can partition at init into a table of cells of size k, T[0..m-1], where m = floor(N/k) For any allocation request, return some T[i] At any time, some cells are in use, some are free; no particular order or pattern to their status

Records of a single size Maintain a free list: singly linked list of cells not in use. No additional memory needed, can use part of cell as pointer to next chunk. Assumes size(cell) > size(pointer) Access as a stack: Pop to allocate, Push on deallocation, thus  (1). Garbage collection problem remains: when is a chunk available to be reclaimed?

Reference counts Suppose we have: 47 x y y

Reference counts Each time the address of a cell is copied, we have another “use” of that memory location Can’t deallocate until all copies of the address have been destroyed. Method for keeping track of the use of cells: maintain a reference count for each cell

Reference Counts x y 47

Reference Counts Cons: Lots of machinery: P <- Q requires Decrement ref count of *P If *P is now 0, deallocate Increment *Q Requires memory in cells for ref count And how big should it be?? Circularity a problem

What else can we do? Mark and sweep garbage collection..