# Writing a Memory Manager

## Recommended Posts

Process Vector
[0][0, 15][50,434]
[1][30, 56]
[2]
[3][5,25]


##### Share on other sites
(please note thast i'm being very misleading and vague in some areas, this is to force you to think for yourself.)

ok, you have a vector of vectors.

Vector(0) will be the first processes vector, up ntil vector(n).

You also have a vectors of arrays. those are arrays which are 2^16 entries big.

When acessing, you look at vector(0), you then check vector(0).vector(0) up to vector(0).vector(n), you look at
*arr[0] and
*arr[2^16]

you represent the memory using a pointer.

If it is >= arr[0] and is <= arr[255], then, you simply acess
arr[pointer - &arr[0]]

And output it.

if it is > arr[255], then search further along (look up Binary Search which you can use to get this into log2n n time).
if it is < arr[0], then saearch closetr to the beginning.

in the vectors, you keep an int, which stores how much of the array has been allocated (or 2^16 if it is all allocated).

What you do, is, if process(n) is requesting memory,
you look at vector(n).vector(up), where up is the last entry in the vector.

If its int is < 2^16, then you simply increment it, and hand back
*arr[pointer++]

deallocation would work, by "handing back", the pointer, and having another two vectors, which are sorted, and which swap the pointers arround.
so if *pointer == &switcha[n], then *pointer = &switchb[n]

This allows you to deallocate memory, by simply shoving it on the list, and having it return a null pointer. you also add an entry, in which the deleated pointer now represents a new spot on the array. (these pointers get swapped forward and backward, on i/o).

From,
Nice coder (sorry, i'm not more specific, but it is you homework).

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978702

• 21
• 14
• 12
• 10
• 12