bit::memory
Public Types | Public Member Functions | Private Member Functions | List of all members
bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier > Class Template Reference

A block allocator that wraps around raw calls to std::malloc and std::free. More...

#include <malloc_block_allocator.hpp>

Inheritance diagram for bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier >:
bit::memory::ebo_storage< GrowthMultiplier > bit::memory::dynamic_size_type< 0, DefaultBlockSize >

Public Types

using default_block_alignment = std::integral_constant< std::size_t, alignof(std::max_align_t)>
 

Public Member Functions

 malloc_block_allocator () noexcept=default
 Default-constructs this malloc_block_allocator. More...
 
template<std::size_t USize = DefaultBlockSize, typename = std::enable_if_t<USize!=dynamic_size>>
 malloc_block_allocator (GrowthMultiplier growth)
 Constructs a malloc_block_allocator with the specified growth policy. More...
 
template<std::size_t USize = DefaultBlockSize, typename = std::enable_if_t<USize==dynamic_size>>
 malloc_block_allocator (block_size_t block_size, GrowthMultiplier growth=GrowthMultiplier{})
 Constructs a malloc_block_allocator with the default block_size. More...
 
 malloc_block_allocator (malloc_block_allocator &&other)=default
 Move-constructs a malloc_block_allocator from another allocator. More...
 
 malloc_block_allocator (const malloc_block_allocator &other)=default
 Copy-constructs a malloc_block_allocator from another allocator. More...
 
malloc_block_allocatoroperator= (malloc_block_allocator &&other)=default
 Move-assigns a malloc_block_allocator from another allocator. More...
 
malloc_block_allocatoroperator= (const malloc_block_allocator &other)=default
 Copy-assigns a malloc_block_allocator from another allocator. More...
 
owner< memory_blockallocate_block () noexcept
 Allocates a malloc'ed memory_block. More...
 
void deallocate_block (owner< memory_block > block) noexcept
 Deallocates a malloc'ed memory_block. More...
 
std::size_t next_block_size () const noexcept
 Queries the next block size expected from this allocator. More...
 
allocator_info info () const noexcept
 Gets the info about this allocator. More...
 

Private Member Functions

constexpr std::size_t value () const noexcept
 Retrieves the value. More...
 

Detailed Description

template<std::size_t DefaultBlockSize, typename GrowthMultiplier = no_growth_multiplier>
class bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier >

A block allocator that wraps around raw calls to std::malloc and std::free.

Template Parameters
DefaultBlockSize
GrowthMultiplier
Satisfies
BlockAllocator
Satisfies
Stateless

Definition at line 69 of file malloc_block_allocator.hpp.

Constructor & Destructor Documentation

◆ malloc_block_allocator() [1/5]

template<std::size_t DefaultBlockSize, typename GrowthMultiplier = no_growth_multiplier>
bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier >::malloc_block_allocator ( )
defaultnoexcept

Default-constructs this malloc_block_allocator.

This is only enabled for non-dynamic new_block_allocators

◆ malloc_block_allocator() [2/5]

template<std::size_t DefaultBlockSize, typename GrowthMultiplier = no_growth_multiplier>
template<std::size_t USize = DefaultBlockSize, typename = std::enable_if_t<USize!=dynamic_size>>
bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier >::malloc_block_allocator ( GrowthMultiplier  growth)
explicit

Constructs a malloc_block_allocator with the specified growth policy.

Note
This constructor only participates in overload resolution if the DefaultBlockSize is not dynamic_size
Parameters
growththe growth policy

◆ malloc_block_allocator() [3/5]

template<std::size_t DefaultBlockSize, typename GrowthMultiplier = no_growth_multiplier>
template<std::size_t USize = DefaultBlockSize, typename = std::enable_if_t<USize==dynamic_size>>
bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier >::malloc_block_allocator ( block_size_t  block_size,
GrowthMultiplier  growth = GrowthMultiplier{} 
)
explicit

Constructs a malloc_block_allocator with the default block_size.

Note
This constructor only participates in overload resolution if the DefaultBlockSize is dynamic_size
Parameters
block_sizethe default the block size

◆ malloc_block_allocator() [4/5]

template<std::size_t DefaultBlockSize, typename GrowthMultiplier = no_growth_multiplier>
bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier >::malloc_block_allocator ( malloc_block_allocator< DefaultBlockSize, GrowthMultiplier > &&  other)
default

Move-constructs a malloc_block_allocator from another allocator.

Parameters
otherthe other malloc_block_allocator to move

◆ malloc_block_allocator() [5/5]

template<std::size_t DefaultBlockSize, typename GrowthMultiplier = no_growth_multiplier>
bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier >::malloc_block_allocator ( const malloc_block_allocator< DefaultBlockSize, GrowthMultiplier > &  other)
default

Copy-constructs a malloc_block_allocator from another allocator.

Parameters
otherthe other malloc_block_allocator to copy

Member Function Documentation

◆ allocate_block()

template<std::size_t DefaultBlockSize, typename GrowthMultiplier = no_growth_multiplier>
owner<memory_block> bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier >::allocate_block ( )
noexcept

Allocates a malloc'ed memory_block.

Returns
a null memory_block

◆ deallocate_block()

template<std::size_t DefaultBlockSize, typename GrowthMultiplier = no_growth_multiplier>
void bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier >::deallocate_block ( owner< memory_block block)
noexcept

Deallocates a malloc'ed memory_block.

Parameters
blockthe block to deallocate

◆ info()

template<std::size_t DefaultBlockSize, typename GrowthMultiplier = no_growth_multiplier>
allocator_info bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier >::info ( ) const
noexcept

Gets the info about this allocator.

This defaults to 'malloc_block_allocator'. Use a named_malloc_block_allocator to override this

Returns
the info for this allocator

◆ next_block_size()

template<std::size_t DefaultBlockSize, typename GrowthMultiplier = no_growth_multiplier>
std::size_t bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier >::next_block_size ( ) const
noexcept

Queries the next block size expected from this allocator.

Returns
the size of the next allocated block

◆ operator=() [1/2]

template<std::size_t DefaultBlockSize, typename GrowthMultiplier = no_growth_multiplier>
malloc_block_allocator& bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier >::operator= ( malloc_block_allocator< DefaultBlockSize, GrowthMultiplier > &&  other)
default

Move-assigns a malloc_block_allocator from another allocator.

Parameters
otherthe other malloc_block_allocator to move
Returns
reference to (*this)

◆ operator=() [2/2]

template<std::size_t DefaultBlockSize, typename GrowthMultiplier = no_growth_multiplier>
malloc_block_allocator& bit::memory::malloc_block_allocator< DefaultBlockSize, GrowthMultiplier >::operator= ( const malloc_block_allocator< DefaultBlockSize, GrowthMultiplier > &  other)
default

Copy-assigns a malloc_block_allocator from another allocator.

Parameters
otherthe other malloc_block_allocator to copy
Returns
reference to (*this)

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