mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-10 02:02:30 +00:00
1.1 KiB
1.1 KiB
The Memory Manager
The manager will init it self if there is no blocks, the manager is model after a double LinkedList and not a List.
Memory Layout
The layout has not preset list or table but rather every item has meta data linking the next and previous item this allows for a robust system.
The data layout looks as follow :
Block|Block|Block etc.
Block =
Meta Data|Data
Meta data =
1 dword (preveus block address start)|1 dword (next block address start)|1 dword (curent[this] block size)| 1 dword (curent[this] block flag)
the final layout looks like this:
4 dword|4 dword|4 dword|4 dword | (size of Block) bytes | 4 dword|4 dword|4 dword | 4 dword | (size of Block) bytes | etc
Note: this means the smallest size an Block can occupy is 129 bytes, 128 bytes for the header and 1 for the smallest data type a byte.
How this system is used.
Allocation
Adding an Block is easy, you simply find the first free block using compare exchange and split it.
Deallocation (free)
Freeing ablock is easy set its flag(in meta data) to 0