MP2 - CPSC-313 / Spring 2011 Machine Problem 2 A Simple...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 | P a g e CPSC--313 / Spring 2011 Machine Problem 2 A Simple Memory Allocator 100 points Introduction In this machine problem, you are to develop a simple memory allocator that implements the functions my_malloc() and my_free(), very similarly to the UNIX calls malloc() and free(). (Let's assume that -- for whatever reason -- you are unhappy with the memory allocator provided by the system.) The objectives of this Machine Problem are: Package a simple module with some static data as a separately compiled unit. Become deeply familiar with pointer management and array management in the C language (or C++ for that matter). Become familiar with standard methods for handling command-line arguments in a C/UNIX environment. Background: Kernel Memory Management: The kernel manages the physical memory both for itself and for the system and user processes. The memory occupied by the kernel code and its data is reserved and is never used for any other purpose. Other physical memory may be used as frames for virtual memory, for buffer caches, and so on. Most of this memory must be allocated and de-allocated dynamically, and an infrastructure must be in place to keep track of which physical memory is in use, and by whom. Ideally, physical memory should look like a single, contiguous segment from which an allocator can take memory portions and return them. This is not the case in most systems. Rather, different segments of physical memory have different properties. For example, DMA may not be able to address physical memory above 16MB. Similarly, the system may contain more physical memory than what can be directly addressed, and the segments above need to be handled using appropriate memory space extension mechanisms. For all these reasons, many operating systems (for example Linux) partition the memory into so-called zones, and treat each zone separately for allocation purposes. Memory allocation requests typically come with a list of zones that can be used to satisfy the request. For example, a particular request may be preferably satisfied from the “normal” zone. If that fails, from the high-memory zone that needs special access mechanisms. Only if that fails too, the allocation may attempt to allocation from the DMA zone. Within each zone, many systems (for example Linux) use a buddy-system allocator to allocate and free physical memory. This is what you will be providing in this machine problem (for a single zone, and of course not at physical memory level). Your Assignment: You are to implement a C++ module (.h and .c files) that realizes a memory allocator as defined by the following file my_allocator.h:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 | P a g e #ifndef _MY_ALLOCATOR_H_ #define _MY_ALLOCATOR_H_ /* File: my_allocator.h */ typedef void * Addr; unsigned int init_allocator(unsigned int _basic_block_size, unsigned int _length); /* This function initializes the memory allocator and makes a portion of '_length' bytes available. The allocator uses a '_basic_block_size' as its minimal unit of allocation. The function returns the
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/14/2012 for the course CSCE 313 taught by Professor Gu during the Spring '11 term at Texas A&M.

Page1 / 5

MP2 - CPSC-313 / Spring 2011 Machine Problem 2 A Simple...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online