Memory Allocator (ITI8510)

Allikas: Lambda
Redaktsioon seisuga 8. aprill 2010, kell 17:01 kasutajalt Irve (arutelu | kaastöö)
Mine navigeerimisribale Mine otsikasti
Real-Time Operating Systems and Systems Programming
[ @ ]

This task will be part of the final grading. Keep the program in directory "rtos/lab2" and name it allocator.c (and don't forget allocator.h for compilation) for it to be found for checking-script.

You have three weeks to complete the task (until April, 29).

Task

Write your own memory allocator which could replace malloc()/free() pair. There are a few requirements:

  • Allocator should re-use freed memory.
  • It should not crash.

Write two functions:

void * Malloc(size_t size)
void Free(void * ptr)

Questions

  • How should I allocate the memory for allocator?

Since the program should handle its memory all by itself, you should use sbrk() function to move the heap pointer (the same thing what malloc does internally). Do not free the memory using sbrk(), just mark it for re-use.

  • What algorithm should I use?

Use either first-fit or best fit algorithm. Joining of nearby blocks is highly recommended. Memory segregation is not needed (you do not have to create classes for larger and smaller allocations).

Testing

There will be a testing program and its details will arrive here when ready.