Memory management system, C/C++ Programming

1. Basic Heap: Each memory location in our model of the RAM will be an instance of type Memory:

2. typedef union Memory_u Memory;

3. union Memory_u{

4. char character;

5. unsigned int size;

6. unsigned long address;

7. };

In each memory location of our simulated heap, which we'll call a memory cell, we can either store actual data (the character field) or other information that is needed for the dynamic memory management.
Each time we allocate some memory on our simulated heap, we need to use at least four (4) consecutive memory cells: 

The first memory cell uses the size field to say how many data memory cells are allocated (we'll call this the head memory cell for our block of allocated memory);

The next memory cell uses the address field to indicate where the head memory cell is for the block of allocated memory that occurs before this current block in the simulated heap. If there are no blocks allocated that are located before this block, the address field will be zero (start of the heap and forbidden memory location);

the next one or more memory cells (defined by the head memory cell) are the actual allocated memory cells for the data (the characters);

the last memory uses the address field to indicate where the next free memory location in the simulated heap is. Since each memory allocation needs at least four consecutive memory cells, the next free memory location must have at least four consecutive free memory cells.

Our simulated heap will simply be an array of Memory in the actual heap. Array index zero (0) will correspond to memory address zero in our simulated heap and is off limits (to read or write) just as memory location zero (NULL) is off limits in your normal programs.

You will implement all of the functions found in nonstdlib.h (found here) that are not already defined in nonstdlib.c (found here). These functions include Memory* initializeHeap(unsigned long size);

// Purpose: allocate memory on the actual heap for our

// simulated heap. Returns a pointer to the first

// memory location that we have reserved for our

// simulated heap

// (This function is partially defined for you )

// (you can add code to it, but do not change )

// (the last line of it in the .c file )

Posted Date: 4/1/2013 2:44:17 AM | Location : United States







Related Discussions:- Memory management system, Assignment Help, Ask Question on Memory management system, Get Answer, Expert's Help, Memory management system Discussions

Write discussion on Memory management system
Your posts are moderated
Related Questions
for object, malloc allocates memory in heap however doesn't invoke object's constructor to initialize the object. new allocates memory & also invokes constructor to initialize the

You are to implement a code cracking system. The system will deploy four processes (p1,p2,p3 & p4) to try to guess the password of an encrypted code. For encryption, we consider th

While spending the summer as a surveyor’s assistant, you decide to write a program that transforms compass headings in degrees (0-360) to compass bearings. A compass bearing consis

Difference between Echo and print statement. print()and echo() are language constructs in PHP, both are used to output strings. Both statements are of almost same Speed. ech

Write a Program to illustrate passing structure to function? # include struct customer { int id; char name[15]; }; void func_struct(struct customer); main() { struct c

A: A smart pointer is a C++ class which mimics a regular pointer in syntax and some semantics, however it does more. Since smart pointers to distinct types of objects tend to have

How can one make it so keys pressed through users are not echoed on the screen? A: It is not a standard C++ feature. C++ doesn't even need your system to have a keyboard or a sc

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Programming an odds betting website Project Description: We want someone to program a odds betting website, Require someone with experience and skills! Skills required are

Relationship between an Array and Pointers. Consider the following. int arr[] = {0,1,2,3,4,5,6,7,8,9}; If we write arr , it is considered as the address of the first elem