Class MmapPool
This allocator allocates memory in regions (multiple of 4 KB for example).
Each region is then splitted in blocks. So it doesn't request the memory
from the operating system on each call, but only if there are no large
enough free blocks in the available regions.
Deallocation works in the same way. Deallocation doesn't immediately
gives the memory back to the operating system, but marks the appropriate
block as free and only if all blocks in the region are free, the complete
region is deallocated.
| | | | | || | | |
| |prev <----------- | || | | |
| R | B | | B | || R | B | |
| E | L | | L | next E | L | |
| G | O | DATA | O | FREE ---> G | O | DATA |
| I | C | | C | <--- I | C | |
| O | K | | K | prev O | K | |
| N | -----------> next| || N | | |
| | | | | || | | |
Methods
Name | Description |
allocate
(size)
|
Allocates size bytes of memory.
|
deallocate
(p)
|
Deallocates a memory block.
|
reallocate
(p, size)
|
Increases or decreases the size of a memory block.
|
allocate
(size)
|
Allocates size bytes of memory.
|
deallocate
(p)
|
Deallocates a memory block.
|
reallocate
(p, size)
|
Increases or decreases the size of a memory block.
|
TODO
- Thread safety (core.atomic.cas)
- If two neighbour blocks are free, they can be merged
- Reallocation shoud check if there is enough free space in the
next block instead of always moving the memory
- Make 64 KB regions mininmal region size on Linux