A Memory Allocator assignment help

computer science

Description

ICS 53, Winter 2017

Lab 3: A Memory Allocator


You will write a program which maintains a heap which you will organize as an

implicit free list. Your program will allow a user to allocate memory, free memory,

and see the current state of the heap. Your program will accept user commands and

execute them. Your program should provide a prompt to the user (“>”) and accept

the following 7 commands.


1. allocate - This function allows the user to allocate a block of memory from

your heap. This function should take one argument, the number of bytes

which the user wants in the payload of the allocated block. This function

should print out a unique block number which is associated with the block of

memory which has just been allocated. The block numbers should increment

each time a new block is allocated. So the first allocated block should be block

number 1, the second is block number 2, etc. Notice that only the allocated

blocks receive block numbers.


Example:

> allocate 10

1

> allocate 5

2

>


2. free - This function allows the user to free a block of memory. This function

takes one argument, the block number associated with the previously

allocated block of memory.

Example:

> allocate 10

1

> free 10

>

When a block is freed its block number is no longer valid. The block number should


not be reused to number any newly allocated block in the future.


3. blocklist - This command prints out information about all of the blocks in your

heap. It takes no arguments. The following information should be printed

about each block:

I. Size

II. Allocated (yes or no)

III. Start address

IV. End address

Addresses should be printed in hexadecimal. The blocks should be printed in the

order in which they are found in the heap.


Related Questions in computer science category