Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/22.

Slides:



Advertisements
Similar presentations
Chapter 12: File System Implementation
Advertisements

Part IV: Memory Management
Pointer applications. Arrays and pointers Name of an array is a pointer constant to the first element whose value cannot be changed Address and name refer.
Chapter 11: File System Implementation
Memory Management (II)
INTRODUCTION OS/2 was initially designed to extend the capabilities of DOS by IBM and Microsoft Corporations. To create a single industry-standard operating.
Informationsteknologi Friday, November 16, 2007Computer Architecture I - Class 121 Today’s class Operating System Machine Level.
Computer Organization and Architecture
CSCI2413 Lecture 6 Operating Systems Memory Management 2 phones off (please)
1 Memory Management in Representative Operating Systems.
 Demand Technology Software, Inc. Memory Leaks Demand Technology 1020 Eighth Avenue South, Suite 6, Naples, FL phone: (941) fax: (941)
Windows 2000 Memory Management Computing Department, Lancaster University, UK.
Windows Memory Architecture 井民全製作. A Process ’ s Virtual Address Space Every Process has its own private virtual address 32-bits processes  4 GB address.
1 Memory Management Chapter 7. 2 Memory Management Subdividing memory to accommodate multiple processes Memory needs to be allocated to ensure a reasonable.
Win32 Programming Lesson 14: Introducing Windows Memory (C Rox…)
CNIT 127: Exploit Development Ch 4: Introduction to Heap Overflows
CS 241 Section Week #9 (11/05/09). Topics MP6 Overview Memory Management Virtual Memory Page Tables.
CE Operating Systems Lecture 17 File systems – interface and implementation.
Swap Space and Other Memory Management Issues Operating Systems: Internals and Design Principles.
UNIX & Windows NT Name: Jing Bai ID: Date:8/28/00.
Windows XP Memory Management Aaron Lanoy and Jason Farnsworth.
Virtual Memory Pranav Shah CS147 - Sin Min Lee. Concept of Virtual Memory Purpose of Virtual Memory - to use hard disk as an extension of RAM. Personal.
File System Implementation
Memory Management Chapter 7.
Chapter 7 Memory Management
Memory Management Chapter 7.
Chapter 3: Windows7 Part 5.
Vytautas Traškevičius Software Engineering
OPERATING SYSTEM CONCEPT AND PRACTISE
Virtual memory.
Memory Management.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Virtual Memory CSSE 332 Operating Systems
Chapter 14: System Protection
Chapter 11: File System Implementation
Operators in c++.
ITEC 202 Operating Systems
File System Implementation
Chapter 11: File System Implementation
Introduction to Computers
CSI 400/500 Operating Systems Spring 2009
Main Memory Management
This pointer, Dynamic memory allocation, Constructors and Destructor
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
File Sharing Sharing of files on multi-user systems is desirable
Chapter 3: Windows7 Part 5.
Chapter 11: File System Implementation
Operating System Concepts
Optimizing Malloc and Free
Machine Independent Features
Chapter 2: System Structures
Chapter 11: File System Implementation
File System B. Ramamurthy B.Ramamurthy 11/27/2018.
Computer Architecture
Directory Structure A collection of nodes containing information about all files Directory Files F 1 F 2 F 3 F 4 F n Both the directory structure and the.
Introduction to the Intel x86’s support for “virtual” memory
Operating Systems.
Memory Management Overview
Virtual Memory Hardware
Lecture 3: Main Memory.
Operating System Chapter 7. Memory Management
File-System Structure
CSE451 Virtual Memory Paging Autumn 2002
Chapter 11: File System Implementation
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/5.
File system : Disk Space Management
COMP755 Advanced Operating Systems
Operating Systems: Internals and Design Principles, 6/E
Structure of Processes
Memory allocation.
Presentation transcript:

Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/22

Memory management Dynadata Copyright, 2014 © DynaData S.A. 2/22

Dynadata Memory management Six sets of memory management functions exist in Win32, all of which were designed to be used independently of one another. Virtual memory functions. A process's virtual address space, system pagefile, system memory and hard disk space Memory-mapped file functions. A process's virtual address space, system pagefile, standard file I/O, System memory and hard disk space Heap memory functions. A process's virtual address space, system memory, process heap resource structure Global heap memory functions. A process's heap resource structure Local heap memory functions. A process's heap resource structure C run-time reference library. A process's heap resource structure Dynadata Copyright, 2014 © DynaData S.A. 3/22

Dynadata Memory management II Determining which function or set of functions to use for managing memory in your Win32™ application is difficult without a solid understanding of how each group of functions works and the overall impact they each have on the Microsoft® Windows NT™ operating system. Dynadata Copyright, 2014 © DynaData S.A. 4/22

Dynadata Memory management III The first version of the Microsoft® Windows™ operating system introduced a method of managing dynamic memory based on a single global heap, which all applications and the system share, and multiple, private local heaps, one for each application. Local and global memory management functions were also provided, offering extended features for this new memory management system. More recently, the Microsoft C run-time (CRT) libraries were modified to include capabilities for managing these heaps in Windows using native CRT functions such as malloc and free. Dynadata Copyright, 2014 © DynaData S.A. 5/22

Dynadata Memory management IV With the addition of the Win32 API, the number of choices increases. Win32 offers three additional groups of functions for managing memory in applications: Memory-mapped file functions Heap memory functions Virtual memory functions. These new functions do not replace the existing memory management functions found in Windows version 3.1; rather, they provide new features that generally make life easier for developers when writing the memory management portions of their applications for Win32. Dynadata Copyright, 2014 © DynaData S.A. 6/22

Memory management V Dynadata Copyright, 2014 © DynaData S.A. 7/22

Heap Memory Every process in Windows NT has one heap called the default heap. Processes can also have as many other dynamic heaps as they wish, simply by creating and destroying them on the fly. The Win32 subsystem uses the default heap for all global and local memory management functions, and the C run-time library uses the default heap for supporting malloc functions. The heap memory functions, which indicate a specific heap by its handle, use dynamic heaps. Dynadata Copyright, 2014 © DynaData S.A. 8/22

Dynadata Heap Memory II The default and dynamic heaps are basically the same thing, but the default heap has the special characteristic of being identifiable as the default. An application can create as many dynamic heaps as it like by simply calling HeapCreate. You must specify the maximum size of the heap so that the function knows how much address space to reserve. Dynadata Copyright, 2014 © DynaData S.A. 9/22

Dynadata Heap Memory III Since an application can have many dynamic heaps in its process, it need a handle to identify each heap to access it. The HeapCreate() function returns a handle witch identify each heap created. Having to identify heaps by handle also makes managing dynamic heaps more difficult than managing the default heap. Dynadata Copyright, 2014 © DynaData S.A. 10/22

Global memory functions GlobalAlloc GlobalDiscard GlobalFlags GlobalFree GlobalHandle GlobalLock GlobalReAlloc GlobalSize GlobalUnlock Dynadata Copyright, 2014 © DynaData S.A. 11/22

Types of Global and Local Memory In the Win32 API, the global and local memory management functions provide two types of memory, MOVEABLE and FIXED. MOVEABLE memory can be further qualified as DISCARDABLE memory. The number of memory handles available for MOVEABLE memory is limited to 65,535 handles. The Win32 subsystem imposes this limitation on each process. This limitation only applies to MOVEABLE memory. You can allocate as many chunks of FIXED memory as you like, provided the memory and address space are available in your process. Dynadata Copyright, 2014 © DynaData S.A. 12/22

Dynadata Virtual Memory Windows NT provides a page-based virtual memory management scheme that allows applications to realize a 32-bit linear address space for 4 gigabytes (GB) of memory. Internally, the system manages all memory in 4096-byte segments called pages. As a result, each application has its own private address space from which it can use the lower 2 GB—the system reserves the upper 2 GB of every process's address space for its own use. Dynadata Copyright, 2014 © DynaData S.A. 13/22

Virtual Memory II The virtual-memory manager (VMM) in Windows NT is a separate process that is primarily responsible for managing the use of physical memory and pagefiles. In previous versions of Windows, an application had to allocate memory before being able to manipulate the addresses in that memory. In Windows NT, the address space of each process is already allocated; whether there is any memory associated with the addresses in the address space is a different issue. 14/22

Virtual Memory III The Win32 virtual memory management functions provide low-level support for independently managing both the addresses and memory of a process. The entire set of Win32 virtual memory functions is: VirtualAlloc and VirtualFree VirtualLock and VirtualUnlock VirtualQuery or VirtualQueryEx VirtualProtect or VirtualProtectEx 15/22

Virtual Memory IV Every address in a process can be thought of as either free, reserved, or committed at any given time. A process begins with all addresses free, meaning they are free to be committed to memory or reserved for future use. Before any free address may be used, it must first be allocated as reserved or committed. Attempting to access an address that is either reserved or free generates an access violation exception. 16/22

Dynadata Virtual Memory V To use reserved addresses, memory must first be committed to the addresses. Committing memory to addresses is similar to reserving it—call VirtualAlloc() with the dwAllocation parameter equal to MEM_COMMIT. Once addresses have been allocated as either reserved or committed, VirtualFree() is the only way to release them—that is, return them to free addresses. Dynadata Copyright, 2014 © DynaData S.A. 17/22

Dynadata Memory mapped files Memory-mapped files (MMFs) offer a unique memory management feature that allows applications to access files on disk in the same way they access dynamic memory—through pointers. With Memory-mapped files an application can map a view of all or part of a file on disk to a specific range of addresses within the process's address space. And once that is done, accessing the content of a memory-mapped file is as simple as dereferencing a pointer in the designated range of addresses. Dynadata Copyright, 2014 © DynaData S.A. 18/22

Dynadata Memory mapped files II So, writing data to a file can be as simple as assigning a value to a dereferenced pointer as in: *pMem = 23; Similarly, reading from a specific location within the file is simply: nTokenLen = *pMem; Dynadata Copyright, 2014 © DynaData S.A. 19/22

Memory mapped files III File mapping is the association of a file's contents with a portion of the virtual address space of a process. The system creates a file-mapping object to maintain this association. A file view is the portion of virtual address space that the process uses to access the file's contents. Dynadata Copyright, 2014 © DynaData S.A. 20/22

Dynadata Memory mapped files IV Processes read from and write to the file view using pointers, just as they would with dynamically allocated memory. Processes can also manipulate the file view with the virtual memory function VirtualProtect(). Dynadata Copyright, 2014 © DynaData S.A. 21/22

Dynadata Memory mapped files IV The file-mapping functions allow a process to create file-mapping objects and file views to easily access and share data. The file cannot reside on a remote computer if you want to share memory between multiple processes. Dynadata Copyright, 2014 © DynaData S.A. 22/22