Events, Memory Management

Similar documents
Robust Memory Management Schemes

Engine Support System. asyrani.com

Heap Management portion of the store lives indefinitely until the program explicitly deletes it C++ and Java new Such objects are stored on a heap

CIS Operating Systems Contiguous Memory Allocation. Professor Qiang Zeng Spring 2018

Run-time Environments -Part 3

Programming Languages

Run-time Environments - 3

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Preview. Memory Management

Memory Management william stallings, maurizio pizzonia - sistemi operativi

In multiprogramming systems, processes share a common store. Processes need space for:

Machine Problem 1: A Simple Memory Allocator

Dynamic Memory Allocation

Motivation for Dynamic Memory. Dynamic Memory Allocation. Stack Organization. Stack Discussion. Questions answered in this lecture:

Memory Allocators. Pradipta De

Part II: Memory Management. Chapter 7: Physical Memory Chapter 8: Virtual Memory Chapter 9: Sharing Data and Code in Main Memory

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Memory Management. Today. Next Time. Basic memory management Swapping Kernel memory allocation. Virtual memory

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

A.Arpaci-Dusseau. Mapping from logical address space to physical address space. CS 537:Operating Systems lecture12.fm.2

Requirements, Partitioning, paging, and segmentation

DOWNLOAD PDF LINKED LIST PROGRAMS IN DATA STRUCTURE

Requirements, Partitioning, paging, and segmentation

CS61C : Machine Structures

Memory Management III Memory Alloca0on

Binding and Storage. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

Memory management. Johan Montelius KTH

Operating System Labs. Yuanbin Wu

Memory Allocation. Static Allocation. Dynamic Allocation. Dynamic Storage Allocation. CS 414: Operating Systems Spring 2008

Main Memory. Electrical and Computer Engineering Stephen Kim ECE/IUPUI RTOS & APPS 1

ECE 598 Advanced Operating Systems Lecture 10

Chapter 8: Memory Management. Operating System Concepts with Java 8 th Edition

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) !

Dynamic Memory Management! Goals of this Lecture!

Memory Management. Memory Management

Optimizing Dynamic Memory Management

CSCI 4500 / 8506 Sample Questions for Quiz 5

6.172 Performance Engineering of Software Systems Spring Lecture 9. P after. Figure 1: A diagram of the stack (Image by MIT OpenCourseWare.

CS420: Operating Systems

Memory Management. Memory Management. G53OPS: Operating Systems. Memory Management Monoprogramming 11/27/2008. Graham Kendall.

Memory Management. Memory Management Requirements

Operating Systems Unit 6. Memory Management

File. File System Implementation. Operations. Permissions and Data Layout. Storing and Accessing File Data. Opening a File

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Dynamic Memory Allocation. Gerson Robboy Portland State University. class20.ppt

Chapter 9 Memory Management Main Memory Operating system concepts. Sixth Edition. Silberschatz, Galvin, and Gagne 8.1

Main Memory and the CPU Cache

6. Which of the following operating systems was the predecessor of Microsoft MS-DOS? a. Dynix b. Minix c. CP/M

Dynamic Memory Management

Virtual Memory COMPSCI 386

CS Operating Systems

CS Operating Systems

Machine Problem 1: A Simple Memory Allocator. 100 points Due date: To Be Announced

CIS Operating Systems Memory Management. Professor Qiang Zeng Fall 2017

CS 62 Practice Final SOLUTIONS

Performance of Various Levels of Storage. Movement between levels of storage hierarchy can be explicit or implicit

Operating Systems and Computer Networks. Memory Management. Dr.-Ing. Pascal A. Klein

Linux Operating System

Segmentation with Paging. Review. Segmentation with Page (MULTICS) Segmentation with Page (MULTICS) Segmentation with Page (MULTICS)

22 File Structure, Disk Scheduling

Chapter 12: File System Implementation

Operating Systems. 11. Memory Management Part 3 Kernel Memory Allocation. Paul Krzyzanowski Rutgers University Spring 2015

1. With respect to space, linked lists are and arrays are.

Lectures 13 & 14. memory management

CS307 Operating Systems Main Memory

First-In-First-Out (FIFO) Algorithm

Review! Lecture 5 C Memory Management !

CS61C : Machine Structures

Hashing file organization

Dynamic Memory Management

Dynamic Memory Allocation. Basic Concepts. Computer Organization 4/3/2012. CSC252 - Spring The malloc Package. Kai Shen

Chapter 10: Case Studies. So what happens in a real operating system?

Programming Assignment 3

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

key h(key) Hash Indexing Friday, April 09, 2004 Disadvantages of Sequential File Organization Must use an index and/or binary search to locate data

C13: Files and Directories: System s Perspective

Paging. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Dynamic Memory Allocation I Nov 5, 2002

Dynamic Memory Allocation: Basic Concepts

Virtual Memory I. Jo, Heeseung

Dynamic Memory Allocation I

Memory Allocation in VxWorks 6.0 White Paper

Memory Management. COMP755 Advanced Operating Systems

Simulation of Memory Management

Selection Queries. to answer a selection query (ssn=10) needs to traverse a full path.

CSE506: Operating Systems CSE 506: Operating Systems

A Hardware Implementation of a High-Performance Memory Allocator

VIRTUAL MEMORY. Operating Systems 2015 Spring by Euiseong Seo

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package

CS61C Midterm Review on C & Memory Management

Introduction to Computer Systems /18 243, fall th Lecture, Oct. 22 th

Processes, Address Spaces, and Memory Management. CS449 Spring 2016

Memory Management (1) Memory Management. CPU vs. memory. No.8. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Memory Management (1) Memory Management

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Operating systems. Part 1. Module 11 Main memory introduction. Tami Sorgente 1

Dynamic Memory Allocation: Basic Concepts

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Transcription:

Events, Memory Management

Events, Memory Management 1. Call back, message pumps 2. Call backs vs messages 3. Memory management

Callback Program registers and event handler program that is called whenever the event occurs. The handler executes its code and the program returns to it state (instruction pointer) prior to the event. Method used by glut for example. Windows calls event handlers Windows Procedures

Message Pumps Program queries system for event (messages), interprets message and call appropriate function using switch. Both Windows and Linux have system level message system, called message queues in both. System Level message queues probably do not have appropriate features

Messages vs Callback Callback require virtual functions: Void Explosion::Update(){ //... GameObjectCollection damagedobjects; g_world.queryobjectsinsphere( GetDamageSphere(),damagedObjects); for each object in damagedobjects){ object.onexplosion();

Messages vs Callback Callbacks require objects to inherit from a common virtual base class with a virtual function for each event type. This makes adding new events, say in a script impossible. Better to have event class and have each object handle event directly as a message.

Messages vs Callback Message Pump can deliver messages to object in order of importance. Message Pump can hold message for a fixed time. Message Pump requires more complex code than Callbacks.

Memory Management Game often use a memory pool instead of the system heap for dynamic memory allocation. Can implement many pools to group objects of similar type and to avoid scattering objects of the same type throughout a general heap, so as to prevent cache misses. Give programmers a handle on memory sizes required so as to set minimum memory requirements.

Memory Management Memory management techniques same as covered in Operating System Sequential fit method. Buddy method Both have free nodes list, used list. Doubly linked list is used for detecting memory leaks

Sequential Fit Allocate: Find a suitable free node: Split off enough to hold data Add node to used list; keep remainder in free list. Return pointer to created used node.

Sequential Fit Deallocate: Add node to used list; keep remainder in free list. Coalesce with left right nodes if possible

Buddy System In a buddy system, the allocator will only allocate blocks of certain sizes, and has many free lists, one for each permitted size. The permitted sizes are usually either powers of two, or form a Fibonacci sequence, such that any block except the smallest can be divided into two smaller blocks of permitted sizes. When blocks are recycled, there may be some attempt to merge adjacent blocks into ones of a larger permitted size (coalescence). To make this easier, the free lists may be stored in order of address. The main advantage of the buddy system is that coalescence is cheap because the "buddy" of any free block can be calculated from its address.

Buddy System Internal Fragmentation:

Buddy System For example, an allocator in a binary buddy system might have sizes of 16, 32, 64,... 64 kb. It might start off with a single block of 64 kb. If the application requests a block of 8 kb, the allocator would check its 8 kb free list and find no free blocks of that size. It would then split the 64 kb block into two block of 32 kb, split one of them into two blocks of 16 kb, and split one of them into two blocks of 8 kb. The allocator would then return one of the 8 kb blocks to the application and keep the remaining three blocks of 8 kb, 16 kb, and 32 kb on the appropriate free lists. If the application then requested a block of 10 kb, the allocator would round this request up to 16 kb, and return the 16 kb block from its free list, wasting 6 kb in the process. A Fibonacci buddy system might use block sizes 16, 32, 48, 80, 128, 208,... bytes, such that each size is the sum of the two preceding sizes. When splitting a block from one free list, the two parts get added to the two preceding free lists. A buddy system can work very well or very badly, depending on how the chosen sizes interact with typical requests for memory and what the pattern of returned blocks is. The rounding typically leads to a significant amount of wasted memory, which is called internal fragmentation. This can be reduced by making the permitted block sizes closer together.

Types of Sequential Fit Allocation: First fit Choose the first free block that fits the data request. Best Fit Try to find exact fitting block. Keep a pointer to best fitting block seen. Others optimal fit, worst fit. Deallocate: Memory location Find free block before and after. Increasing size,decreasing size lists

Memory Management In reviewing game memory management methods, I learned a trick I didn't know: how to construct a double linked list with only one pointer in each node! OGRE Memory Class Boot Memory Management

XOR Trick C=Current node. N = next node. P=Previous node. Store P xor N in Current node. Moving down the list (P xor N) xor P =N. Moving up the list (P xor N) xor N =P.