The goal is to write a dynamic memory allocator, and then compare performance between different CPUs. Not only will this give a somewhat realistic benchmark, it will also result in useful code that people can adopt in their own programs, or use for studying purposes.
The rules:
- The memory allocator is initialized with start/end address of a heap. The size of the heap is in relation to typical memory for the processor (64kB for 65C02/Z80/6809/STM8, 1MB+ for 65816/ARM/x86).
- Two functions/subroutines must be provided:
- An 'alloc' routine, which takes a size argument, and returns the address of a suitable block, or an error code (e.g. 0 value), when no suitable block is available.
- A 'free' routine which takes the address of a previously allocated block, and adds it back to the heap.
- The allocator must use a 'best fit' algorithm, which means that it should keep all free blocks in a list, find the one that is closest to the required amount, and return that. If the block is bigger than the required amount, the block should be split in two, and the remainder placed back on the free list for future allocations. When the 'free' function is called, little blocks should be combined into bigger blocks as much as possible.
- Apart from the heap itself, the allocator should only use a small static amount of memory.
- Code must run from ROM. Self-modifying code is allowed, but it needs to be copied to RAM first.
- You must allow for the heap to be as big as all available memory on the chosen platform (ZP and stack excluded).
- A single allocation may successfully request all free memory in one time, with maximum of 64 kB.
Anybody interested ?