Here's a very simple malloc implementation. Fits in a couple hundreed bytes of flash.
Here are pluses and minuses.
Plus:
•Very small flash usage.
•Easy to integrate into project/CircleOS
•Easy to follow up with adding permission pages and segmenting memory to differend processes.
•Very fast free implementation: O(1). One comparison, one division, one assigment.
•O(n) malloc, where n are half fragmented single pages. Maximum wait time is 42 microseconds in the worst case scenario (request for 2 pages, having one page all written before it. Theoretical calculations, which exclude any pipelining.). Expected time depends primarily on memory usage.
•Big pages are treated as one big page instead of many small ones thus we are able to jump around it when looking for pages.
Minus:
•Only returns multiples of 128 and above. Thus if you want to malloc 2x64 then you should do...
•Consumes 2% of RAM (2 bytes/bucket * 100% / Bucket_size) = 200 / 128 = 1.6%, but this is higher due to linker having to align this to powers of two boundary.
Now, I started working on splitting up pages and requests to map specific memory, with a tree implementation. However, there's quite a few things that would be nice to change with the CircleOS. It's not a good OS. As of now it supports neither preemptive nor cooperative multitasking without jumping through hoops. Why can't we just implement the systick to have threads it can call and have the threads have other resolutions other than MENU_leave, and continue?