Sources Pipelines Documentation

Allocators  
Classes | Public Member Functions | List of all members
boost::memory::free_list< allocator, batch_size, min, max, capacity > Class Template Reference

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

Detailed Description

template<typename allocator, std::size_t batch_size, std::size_t min, std::size_t max, std::size_t capacity>
class boost::memory::free_list< allocator, batch_size, min, max, capacity >

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.

Template Parameters
allocatorUnderlying allocator used to actually allocate the blocks hold by the list.
batch_sizeNumber of allocation which should be requested from the underlying allocator in event the list is empty.
minMinimal size of a block requested from the list.
maxMaximal size of a block requested from the list.
capacityCapacity 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.

Member Function Documentation

template<typename allocator , std::size_t batch_size, std::size_t min, std::size_t max, std::size_t capacity>
memory_block boost::memory::free_list< allocator, batch_size, min, max, capacity >::allocate ( std::size_t  size)
inline

Allocates a memory_block from either the list or using the underlying allocator.

Parameters
sizeRequested block size.
Returns
Either allocated memory_block or *{ nullptr, 0ul }* is block can't be allocated.

Definition at line 93 of file free_list.ipp.

template<typename allocator , std::size_t batch_size, std::size_t min, std::size_t max, std::size_t capacity>
void boost::memory::free_list< allocator, batch_size, min, max, capacity >::deallocate ( memory_block block)
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.

Parameters
blockThe memory_block to be recycled.

Definition at line 148 of file free_list.ipp.

template<typename allocator , std::size_t batch_size, std::size_t min, std::size_t max, std::size_t capacity>
bool boost::memory::free_list< allocator, batch_size, min, max, capacity >::owns ( memory_block block)
inline

Determines if the list owns the block.

Parameters
blockThe block to check.
Returns
true if the block has been allocated from this list, false otherwise.

Definition at line 172 of file free_list.ipp.

Referenced by boost::memory::free_list< allocator, batch_size, min, max, capacity >::deallocate().


The documentation for this class was generated from the following files: