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.

Slides:



Advertisements
Similar presentations
Chapter 12: File System Implementation
Advertisements

Paging: Design Issues. Readings r Silbershatz et al: ,
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Allocation Methods - Contiguous
1 Chapter 11: File-System Interface  File Concept  Access Methods  Directory Structure  File System Mounting  File Sharing  Protection  Chapter.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
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 11: File System Implementation
File System Implementation
File System Implementation
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
File System Implementation CSCI 444/544 Operating Systems Fall 2008.
Chapter 12: File System Implementation
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.
Memory Management 2010.
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.
Chapter 12: File System Implementation
Computer Organization and Architecture
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
File System Implementation
 2004 Deitel & Associates, Inc. All rights reserved. Chapter 9 – Real Memory Organization and Management Outline 9.1 Introduction 9.2Memory Organization.
Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access memory.
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.
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Chapter Languages, Programming and Architecture.
Chapter 3.1:Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 8: Main Memory.
File I/O Applied Component-Based Software Engineering File I/O CSE 668 / ECE 668 Prof. Roger Crawfis.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
File Systems CSCI What is a file? A file is information that is stored on disks or other external media.
Chapter 11: File System Implementation Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 1, 2005 File-System Structure.
Basic Semantics Associating meaning with language entities.
Lecture 11 Page 1 CS 111 Online Memory Management: Paging and Virtual Memory CS 111 On-Line MS Program Operating Systems Peter Reiher.
Chapter 4 Memory Management Virtual Memory.
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.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
12.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 12: File System Implementation Chapter 12: File System Implementation.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
CE Operating Systems Lecture 17 File systems – interface and 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.
File Systems cs550 Operating Systems David Monismith.
C++ 程序语言设计 Chapter 12: Dynamic Object Creation. Outline  Object creation process  Overloading new & delete.
Lecture 7 Page 1 CS 111 Summer 2013 Another Option Fixed partition allocations result in internal fragmentation – Processes don’t use all of the fixed.
FILE SYSTEM IMPLEMENTATION 1. 2 File-System Structure File structure Logical storage unit Collection of related information File system resides on secondary.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Memory Management Chapter 5 Advanced Operating System.
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.
File System Implementation
Object Lifetime and Pointers
Chapter 8: Main Memory.
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.
Chapter 9: Virtual Memory – Part I
Outline Paging Swapping and demand paging Virtual memory.
Chapter 9 – Real Memory Organization and Management
CSI 400/500 Operating Systems Spring 2009
Chapter 8: Main Memory.
Operation System Program 4
Chapter 9: Virtual-Memory Management
Memory Allocation CS 217.
CS510 Operating System Foundations
COMP755 Advanced Operating Systems
Presentation transcript:

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 with explicit memory management (C or C++) In garbage collecting languages (e.g. Java, Python, Unicon) you may still have leaks due to OS, memory reference cycles, or live-but-never used data

3 Memory Management We have three goals when working with memory Safety Knowledge Control

4 Memory Management Memory fragmentation Free physical memory is only available in chunks Can prevent an allocation from completing successfully even if there's plenty of free memory Virtual addressing helps with fragmentation problems

5 Memory Management Virtual addressing

6 Memory Management “Static” memory allocation Really means: globals + stack If all memory is statically allocated there will be very few problems. Mostly rules out: Leaks Fragmentation Running out of memory Very restrictive Lots of underutilized memory Many old games were done this way

7 Memory Management “Dynamic” allocation Really, this is talking about heap allocation Much more flexible than static allocations Lots of potential problems Often: override global new and delete to control allocations

8 Memory Management Memory manager Heaps are large collections of memory allocated for arbitrary mixed uses Managed by language runtime system Especially in C/C++: simple error-checking schemes reduce memory overrun problems Slow and wasteful of memory for lots of small objects

9 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 memory leaks, look for all the allocations that occurred between two particular points in time

10 Memory Management Memory pools Memory pools are contiguous blocks of memory used to allocate objects Allocations are extremely fast There is no fragmentation... Except for all the unused space We can allocate objects from specific classes with a simple macro

11 Memory Management Memory pools

12 File I/O Full file I/O (e.g. reading/writing local named files) not always available Many different API’s and speeds of accessing different devices Memory cards, network, etc Game developer usually has no control over physical disk allocation Which can lead to long load times

13 File I/O Unified file system Platform independent Provide same interface to different types of media Based around FileSystem class

14 File I/O File system 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

15 File I/O File system

16 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 easily There will be many different types of resources in a game

17 Game Resources Resource manager Uses registering object factory pattern Can register different types of resources All resource creation goes through the resource manager Requests for existing resources usually don't have to load it again Basically a giant in-memory cache

18 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 of the game needs to keep on its own This is exactly the flywheel design pattern

19 Game Resources Resource lifetime How do we know when we can destroy shared resources? All at once At the end of the level Explicit lifetime management Reference counting, garbage collection GPU resources may be managed differently than CPU resources

20 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

21 Serialization Saving [I]Serializable interface for read and write operations Each class implements a Write() (or writeObject(), etc) function Saving pointers is a problem They won't be the same when we load So save an ID of some kind Saving open OS handles is also no good

22 Serialization Loading Create object types through an object factory Read() function takes care of loading the data from the stream, assigning IDs stored in file with newly created objects/pointers Pointers are loaded into a translation table Second pass fixes up all the pointers