Chapter 3.5 Memory and I/O Systems. Memory Management 2 Only applies to languages with explicit memory management (C, C++) Memory problems are one of.

Slides:



Advertisements
Similar presentations
Chapter 12: File System Implementation
Advertisements

Data Structures Static and Dynamic.
Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Copyright © 2000, Daniel W. Lewis. All Rights Reserved. CHAPTER 9 MEMORY MANAGEMENT.
File Systems.
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Chapter 11 File-System Interface
Chapter 11: File System Implementation
File System Implementation
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CS-334: Computer.
Operating System Support Focus on Architecture
File System Implementation CSCI 444/544 Operating Systems Fall 2008.
Memory Management 2010.
Chapter 3.2 : Virtual Memory
Chapter 9 Virtual Memory Produced by Lemlem Kebede Monday, July 16, 2001.
Chapter 3.7 Memory and I/O Systems. 2 Memory Management Only applies to languages with explicit memory management (C or C++) Memory problems are one of.
Computer Organization and Architecture
File System Implementation
CS364 CH08 Operating System Support TECH Computer Science Operating System Overview Scheduling Memory Management Pentium II and PowerPC Memory Management.
Layers and Views of a Computer System Operating System Services Program creation Program execution Access to I/O devices Controlled access to files System.
Chapter Languages, Programming and Architecture.
Real-Time Concepts for Embedded Systems Author: Qing Li with Caroline Yao ISBN: CMPBooks.
Chapter 3 Memory Management: Virtual Memory
Dynamic Partition Allocation Allocate memory depending on requirements Partitions adjust depending on memory size Requires relocatable code –Works best.
Chapter 5 Operating System Support. Outline Operating system - Objective and function - types of OS Scheduling - Long term scheduling - Medium term scheduling.
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.
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
File Systems CSCI What is a file? A file is information that is stored on disks or other external media.
IT253: Computer Organization
Memory Management – Page 1 of 49CSCI 4717 – Computer Architecture Memory Management Uni-program – memory split into two parts –One for Operating System.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
1 File Management Chapter File Management n File management system consists of system utility programs that run as privileged applications n Concerned.
8.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Paging Physical address space of a process can be noncontiguous Avoids.
1 Advanced Memory Management Techniques  static vs. dynamic kernel memory allocation  resource map allocation  power-of-two free list allocation  buddy.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 12: File System Implementation File System Structure File System Implementation.
File System Implementation
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 11: File System Implementation.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition File System Implementation.
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
I MPLEMENTING FILES. Contiguous Allocation:  The simplest allocation scheme is to store each file as a contiguous run of disk blocks (a 50-KB file would.
C++ 程序语言设计 Chapter 12: Dynamic Object Creation. Outline  Object creation process  Overloading new & delete.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Overloading operators C++ incorporates the option to use standard operators to perform operations with.
11.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 11.5 Free-Space Management Bit vector (n blocks) … 012n-1 bit[i] =  1  block[i]
Lecture 7 Page 1 CS 111 Summer 2013 Dynamic Domain Allocation A concept covered in a previous lecture We’ll just review it here Domains are regions of.
FILE SYSTEM IMPLEMENTATION 1. 2 File-System Structure File structure Logical storage unit Collection of related information File system resides on secondary.
Lecture 10 Page 1 CS 111 Online Memory Management CS 111 On-Line MS Program Operating Systems Peter Reiher.
Operating Systems Lecture 9 Introduction to Paging Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of.
Computer Architecture Chapter (8): Operating System Support
File-System Management
Object Lifetime and Pointers
Chapter 2 Memory and process management
Game Architecture Rabin is a good overview of everything to do with Games A lot of these slides come from the 1st edition CS 4455.
Paging COMP 755.
Dynamic Domain Allocation
Chapter 11: File System Implementation
Chapter 9 – Real Memory Organization and Management
William Stallings Computer Organization and Architecture
CSI 400/500 Operating Systems Spring 2009
Chapter 8: Main Memory.
Chapter 11: File System Implementation
Page Replacement.
Chapter 11: File System Implementation
Memory Allocation CS 217.
Chapter 14: File-System Implementation
Chapter 11: File System Implementation
COMP755 Advanced Operating Systems
Lecture Topics: 11/20 HW 7 What happens on a memory reference Traps
Presentation transcript:

Chapter 3.5 Memory and I/O Systems

Memory Management 2 Only applies to languages with explicit memory management (C, C++) Memory problems are one of the leading causes of bugs in programs Leaks Buffer Overflows (Improper Access) Fragmentation

Memory Management 3 We have 3 goals when working with memory: 1. Safety – Find fix leaks – Protect data 2. Knowledge – Who, what, where, how much 3. Control – Location → Caching → Speed

Memory Fragmentation 4 Free physical memory is only available in small sections Can prevent an allocation from completing successfully even if there's plenty of free memory Virtual addressing will greatly help with fragmentation problems

Virtual Addressing 5 Virtual addressing "Lying to your applications since 1961"

Static Allocation 6 Static memory allocation: If all memory is statically allocated at start there will be very few problems: No - Leaks (no malloc, new, delete, free) No - Fragmentation No - Running out of memory Has disadvantages though: Very restrictive (everything predeclared) Lots of wasted memory Old games used to be done this way

Static Allocation Example // Create a fixed number of pathnodes #define MAX_PATHNODES 4096 AIPathNode max_PathNodes[MAX_PATHNODES]; // Create a fixed size butter for Geometry calculations // 8MB in size #define GEOMSIZE (8*1024*1024) byte* s_GeomBuffer[GEOMSIZE ];

Dynamic Allocation 8 Dynamic allocation is much more flexible than static allocations: But has lots of potential problems Leaks, Miss-allocations Tracking difficulties Need to override/replace new and delete to take control over allocations

Key Concept #1 1. "new" is actually broken down by the compiler into many sub-steps. MyClass *data = new MyClass(); // Equivalent too MyClass *data = malloc(sizeof(MyClass)); *data -> MyClass(); // malloc() in turn is broken down into several calls.

Key Concept #2 2. “new” and “delete” are just operators (like +, <, =) and operators can be changed and overloaded. CVector::CVector (int a, int b) { x = a; y = b; } CVector CVector::operator+ (CVector param) { CVector temp; temp.x = x + param.x; temp.y = y + param.y; return (temp); }

Key Concept #3 3. We can overload new (and delete) so that they create and manage receipts (allocation headers) for all dynamically created objects. void * operator new (size_t size, Heap *pHeap); Struct AllocHeader { int nSignature, nAllocnum, nSize; Heap *pHeap; AllocHeader * pNext; AllocHeader * pPrev; }

Key Concept #4 3. We can overload new (and delete) so that return/release a pointer to an existing (statically defined) memory location [ using Alloc() ], rather then using malloc to create a new one. Class MemoryPool { … Void * Alloc (size_t nSize)

Memory Manager Heaps are collections of data sorted by size. We can use a heap to monitor memory allocations We will need to override operator new and delete We can add some simple error-checking schemes to prevent memory overrun problems 13

Memory Management Memory leaks A memory leak is a memory allocation that is no longer necessary and was not released by the program Memory leaks can cause the game to use up resources and run out of memory To find all memory leaks, we look for all the allocations that occurred between two particular points in time 14

Memory Management Memory pools Memory pools are contiguous blocks of memory used to allocate objects Allocations are extremely fast There is no fragmentation They will usually have some unused space We can allocate objects from specific classes with a simple macro 15

Memory Management Memory pools 16

File I/O 17 Sometimes full file I/O not available on all platforms Different ways of accessing different devices Different speeds of access Memory cards, network, etc Usually have no control over physical disk allocation Which can lead to long load times Ultimate goal is too simplify and speed-up File I/O

File I/O Desire unified file system Platform independent Provide same interface to different types of media Based around FileSystem class Allow us to “buffer data” as desired Including moving data to main memory 18

File I/O File system class Uses concept of streams Stream can be the source of data Possible sources File, memory, network Or it can be a layer that adds some properties Possible layers Buffering, compression, range, etc 19

File I/O File system 20

Pack Files Fast Processor & Slow File I/O Perfect time to use compression Cab, zip, rar or custom. Pack files can yield caching advantages Grouping related data Improve cached hit if large sections buffered

Game Resources A game resource (or asset) is anything that gets loaded that could be shared by several parts of the game A texture, an animation, a sound, etc We want to load and share resources quickly and easily avoid File I/O There will be many different types of resources in a game 22

Game Resources Resource manager Uses registering object factory pattern Can register different types of resources All resource creation goes through the resource manager Any requests for existing resources don't load it again Pre-caching possible/desirable 23

Game Resources Resource lifetime If resources are shared, how do we know when we can destroy them? All at once At the end of the level Explicit lifetime management Reference counting Smart Pointers 24

Game Resources Resources and instances Resource is the part of the asset that can be shared among all parts of the game Instance is the unique data that each part (object) of the game needs to keep Pointers can be used to keep instance data that references shared resource data 25

Serialization Every game needs to save and restore some game state Even for check point saves Level editing and creation could be implemented as a saved game How do we effectively store state information for objects? 26

Serialization Saving ISerializable interface (pure virtual functions) for Read and Write operations Each class implements the Write() function Saving pointers is a problem They won't be the same when we load Save raw pointers to other objects Translate them later Save UID information (always valid) 27

Serialization Loading Create object types through an object factory Read() function takes care of loading the stored data from the stream Pointers are then loaded into a translation table Second pass fixes up all the pointers 28

The end 29