virtual_block_allocator Class Reference
Allocator implementations

## Detailed Description

A BlockAllocator that reserves virtual memory and commits it part by part.

It is similar to memory_stack but does not support growing and uses virtual memory, also meant for big blocks not small allocations.

## Member Functions

| virtual_block_allocator (std::size_t block_size, std::size_t no_blocks)
| ~virtual_block_allocator () noexcept
memory_block | allocate_block ()
void | deallocate_block (memory_block block) noexcept
std::size_t | next_block_size () const noexcept
std::size_t | capacity_left () const noexcept
| virtual_block_allocator (virtual_block_allocator &&other) noexcept
virtual_block_allocator & | operator= (virtual_block_allocator &&other) noexcept

## Constructors

## virtual_block_allocator() [1/2]

virtual_block_allocator | ( | std::size_t | block_size,
|  | std::size_t | no_blocks
| ) |  |

explicit

Effects:
  Creates it giving it the block size and the total number of blocks it can allocate. It reserves enough virtual memory for `block_size * no_blocks`.

Requires:
  `block_size` must be non-zero and a multiple of the virtual_memory_page_size. `no_blocks` must be bigger than `1`.

Throws:
  out_of_memory if it cannot reserve the virtual memory.

## ~virtual_block_allocator()

~virtual_block_allocator | ( |  | ) |

noexcept

Effects:
  Releases the reserved virtual memory.

Requires:
  All previously allocate_block() committed blocks must be decommitted via deallocate_block(), otherwise the blocks that have not been deallocated are leaked.

## virtual_block_allocator() [2/2]

virtual_block_allocator | ( | virtual_block_allocator && | other | ) |

noexcept

Effects:
  Moves the block allocator, it transfers ownership over the reserved area. This does not invalidate any memory blocks.

## Member Functions

## operator=()

virtual_block_allocator & operator= | ( | virtual_block_allocator && | other | ) |

noexcept

Effects:
  Moves the block allocator, it transfers ownership over the reserved area. This does not invalidate any memory blocks.

## allocate_block()

memory_block allocate_block | ( |  | ) |

Effects:
  Allocates a new memory block by committing the next next_block_size() number of bytes.

Returns:
  The memory_block committed.

Throws:
  out_of_memory if it cannot commit the memory or the capacity_left() is exhausted.

## deallocate_block()

void deallocate_block | ( | memory_block | block | ) |

noexcept

Effects:
  Deallocates the last allocated memory block by decommitting it. This block will be returned again on the next call to allocate_block().

Requires:
  `block` must be the current top block of the memory, this is guaranteed by memory_arena.

## next_block_size()

std::size_t next_block_size | ( |  | ) | const

noexcept

Returns:
  The next block size, this is the block size of the constructor.

## capacity_left()

std::size_t capacity_left | ( |  | ) | const

noexcept

Returns:
  The number of blocks that can be committed until it runs out of memory.