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

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

Members

Functions

allocate
void[] allocate(size_t size)

Allocates size bytes of memory.

deallocate
bool deallocate(void[] p)

Deallocates a memory block.

reallocate
bool reallocate(void[] p, size_t size)

Increases or decreases the size of a memory block.

Properties

alignment
immutable(uint) alignment [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
instance
MmapPool instance [@property getter]

Static allocator instance and initializer.

Static functions

initialize
initialize()
Undocumented in source. Be warned that the author may not have intended to support it.

Inherited Members

From Allocator

allocate
void[] allocate(size_t size)

Allocates size bytes of memory.

deallocate
bool deallocate(void[] p)

Deallocates a memory block.

reallocate
bool reallocate(void[] p, size_t size)

Increases or decreases the size of a memory block.

alignment
immutable(uint) alignment [@property getter]

Meta