Memory Allocator (ITI8510): erinevus redaktsioonide vahel

Allikas: Lambda
Mine navigeerimisribale Mine otsikasti
Resümee puudub
Resümee puudub
1. rida: 1. rida:
{{iti8510}}
{{iti8510}}
This task will be part of the final grading.
This task will be part of the final grading. Keep the program in directory "rtos/lab2" and name it allocator.c for it to be found for checking-script.
 
You have '''three weeks''' to complete the task (until 29. april).


== Task ==
== Task ==
19. rida: 21. rida:


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).
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.

Redaktsioon: 8. aprill 2010, kell 15:05

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 for it to be found for checking-script.

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

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.