![]() |
Allocators
|
Provides mechanism for reusing deallocated memory blocks. More...
#include <free_list.hpp>
Public Member Functions | |
memory_block | allocate (std::size_t size) |
Allocates a memory_block from either the list or using the underlying allocator. More... | |
void | deallocate (memory_block &block) |
Deallocates the given memory_block. More... | |
bool | owns (memory_block &block) |
Determines if the list owns the block. More... | |
Provides mechanism for reusing deallocated memory blocks.
Intention of this allocator is to recycle memory blocks allocated with the backing allocator and possibly use them again when requested. The list starts empty. Then on the first request a batch of memory_block*s are allocated and placed in the list. The first block is returned immediately as an allocated block the subsequently allocated blocks are returned further on on subsequent *allocate calls. Once a block is returned to the list through deallocate call, it's placed at the head of the list, so it'll be used on the very next allocate request. This keeps the caches warm. The list defines its capacity over which blocks can't be allocated by the underlying allocator. This mechanism prevents the list from indefinite growth as allocated blocks can't be destroyed.
allocator | Underlying allocator used to actually allocate the blocks hold by the list. |
batch_size | Number of allocation which should be requested from the underlying allocator in event the list is empty. |
min | Minimal size of a block requested from the list. |
max | Maximal size of a block requested from the list. |
capacity | Capacity of the list. Defines to upper watermark for number of allocations which can be performed with the underlying allocator. |
Definition at line 84 of file free_list.hpp.
|
inline |
Allocates a memory_block from either the list or using the underlying allocator.
size | Requested block size. |
Definition at line 93 of file free_list.ipp.
|
inline |
Deallocates the given memory_block.
A block can be deallocated only if it's been allocated by the underlying allocator. Deallocated block isn't physically deallocated by the underlying allocator, but instead is added to the head of the list and recycled on the next allocation.
block | The memory_block to be recycled. |
Definition at line 148 of file free_list.ipp.
|
inline |
Determines if the list owns the block.
block | The block to check. |
Definition at line 172 of file free_list.ipp.
Referenced by boost::memory::free_list< allocator, batch_size, min, max, capacity >::deallocate().