bit::memory
Public Types | Public Member Functions | List of all members
bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable > Class Template Reference

This allocator manages policy-based memory allocation strategies using policy-based-design. More...

#include <policy_allocator.hpp>

Inheritance diagram for bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >:
bit::memory::ebo_storage< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >

Public Types

using default_alignment = allocator_default_alignment< ExtendedAllocator >
 
using max_alignment = allocator_max_alignment< ExtendedAllocator >
 
using lock_type = BasicLockable
 
using tracker_type = MemoryTracker
 

Public Member Functions

template<typename... Args, typename = std::enable_if_t<std::is_constructible<ExtendedAllocator,Args...>::value>>
 policy_allocator (Args &&...args)
 Constructs an policy_allocator by forwarding all arguments to the underlying ExtendedAllocator. More...
 
 policy_allocator (policy_allocator &&other)=default
 Move-constructs this policy_allocator from another allocator. More...
 
 policy_allocator (const policy_allocator &other)=default
 Copy-constructs this policy_allocator from another allocator. More...
 
 ~policy_allocator ()
 Destructs the policy allocator, checking for any leaks.
 
policy_allocatoroperator= (policy_allocator &&other)=default
 Move-assigns this policy_allocator from another allocator. More...
 
policy_allocatoroperator= (const policy_allocator &other)=default
 Copy-assigns this policy_allocator from another allocator. More...
 
const tracker_type & tracker () const noexcept
 Accesses the tracker from the policy_allocator. More...
 
void * try_allocate (std::size_t size, std::size_t align) noexcept
 Attempts to allocate size bytes aligned to a boundary of align using the underlying allocator. More...
 
void deallocate (void *p, std::size_t size)
 Deallocates the pointer p with the size size. More...
 
template<typename U = ExtendedAllocator, typename = std::enable_if_t<allocator_can_truncate_deallocations<U>::value>>
void deallocate_all ()
 Deallocates all memory in this allocator. More...
 
template<typename U = ExtendedAllocator, typename = std::enable_if_t<allocator_knows_ownership<U>::value>>
bool owns (const void *p) const noexcept
 Checks if p is owned by the underlying allocator. More...
 
template<typename U = ExtendedAllocator, typename = std::enable_if_t<allocator_has_info<U>::value>>
allocator_info info () const noexcept
 Retrieves info about this allocator. More...
 
template<typename U = ExtendedAllocator, typename = std::enable_if_t<allocator_has_max_size<U>::value>>
std::size_t max_size () const noexcept
 Gets the maximum size allocateable from this allocator. More...
 
template<typename U = ExtendedAllocator, typename = std::enable_if_t<allocator_has_min_size<U>::value>>
std::size_t min_size () const noexcept
 Gets the minimum size allocateable from this allocator. More...
 

Detailed Description

template<typename ExtendedAllocator, typename MemoryTagger, typename MemoryTracker, typename BoundsChecker, typename BasicLockable>
class bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >

This allocator manages policy-based memory allocation strategies using policy-based-design.

It is comprised of debugger types that better help memory allocation strategies, while also supporting

Note
Since this is an policy allocator, it is not possible for all of the underlying policies to be stateless (since something must keep track of the used blocks); thus this class does not default itself to being stateless
Satisfies
Allocator
Template Parameters
ExtendedAllocatorAn allocator that satisfies the ExtendedAllocator concept
MemoryTaggerA class used for tagging memory on allocations and on deallocations.
MemoryTrackerA class used for tracking memory allocations.
BoundsCheckerA class used for bounds checking; used to catch buffer-overflow issues
BasicLockableA lockable type for thread-synchronization

Definition at line 81 of file policy_allocator.hpp.

Constructor & Destructor Documentation

◆ policy_allocator() [1/3]

template<typename ExtendedAllocator , typename MemoryTagger , typename MemoryTracker , typename BoundsChecker , typename BasicLockable >
template<typename... Args, typename = std::enable_if_t<std::is_constructible<ExtendedAllocator,Args...>::value>>
bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >::policy_allocator ( Args &&...  args)

Constructs an policy_allocator by forwarding all arguments to the underlying ExtendedAllocator.

Parameters
argsthe arguments to forward to the ExtendedAllocator

◆ policy_allocator() [2/3]

template<typename ExtendedAllocator , typename MemoryTagger , typename MemoryTracker , typename BoundsChecker , typename BasicLockable >
bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >::policy_allocator ( policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable > &&  other)
default

Move-constructs this policy_allocator from another allocator.

Note
This constructor is only enabled if ExtendedAllocator is stateless
Parameters
otherthe other allocator to move

◆ policy_allocator() [3/3]

template<typename ExtendedAllocator , typename MemoryTagger , typename MemoryTracker , typename BoundsChecker , typename BasicLockable >
bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >::policy_allocator ( const policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable > &  other)
default

Copy-constructs this policy_allocator from another allocator.

Note
This constructor is only enabled if ExtendedAllocator is stateless
Parameters
otherthe other allocator to copy

Member Function Documentation

◆ deallocate()

template<typename ExtendedAllocator , typename MemoryTagger , typename MemoryTracker , typename BoundsChecker , typename BasicLockable >
void bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >::deallocate ( void *  p,
std::size_t  size 
)

Deallocates the pointer p with the size size.

Parameters
pthe pointer to deallocate
sizethe size originally requested to 'try_allocate'

◆ deallocate_all()

template<typename ExtendedAllocator , typename MemoryTagger , typename MemoryTracker , typename BoundsChecker , typename BasicLockable >
template<typename U = ExtendedAllocator, typename = std::enable_if_t<allocator_can_truncate_deallocations<U>::value>>
void bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >::deallocate_all ( )

Deallocates all memory in this allocator.

Note
This function is only enabled if the underlying ExtendedAllocator supports it

◆ info()

template<typename ExtendedAllocator , typename MemoryTagger , typename MemoryTracker , typename BoundsChecker , typename BasicLockable >
template<typename U = ExtendedAllocator, typename = std::enable_if_t<allocator_has_info<U>::value>>
allocator_info bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >::info ( ) const
noexcept

Retrieves info about this allocator.

Note
This function is only enabled if the underlying ExtendedAllocator supports it
Returns
the info about this allocator

◆ max_size()

template<typename ExtendedAllocator , typename MemoryTagger , typename MemoryTracker , typename BoundsChecker , typename BasicLockable >
template<typename U = ExtendedAllocator, typename = std::enable_if_t<allocator_has_max_size<U>::value>>
std::size_t bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >::max_size ( ) const
noexcept

Gets the maximum size allocateable from this allocator.

Note
the max_size does not guarantee that the size is able to be allocated at the time the value is queried; it just means that it is the maximum size that the allocator is capable of allocating from an empty state.
Parameters
allocthe allocator to get the max size from
Returns
the amount of bytes available for the largest possible allocation

◆ min_size()

template<typename ExtendedAllocator , typename MemoryTagger , typename MemoryTracker , typename BoundsChecker , typename BasicLockable >
template<typename U = ExtendedAllocator, typename = std::enable_if_t<allocator_has_min_size<U>::value>>
std::size_t bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >::min_size ( ) const
noexcept

Gets the minimum size allocateable from this allocator.

Note
The default is 1, if this function is not defined
Parameters
allocthe allocator to get the min size from
Returns
the minimum amount of bytes able to allocated

◆ operator=() [1/2]

template<typename ExtendedAllocator , typename MemoryTagger , typename MemoryTracker , typename BoundsChecker , typename BasicLockable >
policy_allocator& bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >::operator= ( policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable > &&  other)
default

Move-assigns this policy_allocator from another allocator.

Note
This assignment is only enabled if ExtendedAllocator is stateless
Parameters
otherthe other allocator to move

◆ operator=() [2/2]

template<typename ExtendedAllocator , typename MemoryTagger , typename MemoryTracker , typename BoundsChecker , typename BasicLockable >
policy_allocator& bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >::operator= ( const policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable > &  other)
default

Copy-assigns this policy_allocator from another allocator.

Note
This assignment is only enabled if ExtendedAllocator is stateless
Parameters
otherthe other allocator to copy

◆ owns()

template<typename ExtendedAllocator , typename MemoryTagger , typename MemoryTracker , typename BoundsChecker , typename BasicLockable >
template<typename U = ExtendedAllocator, typename = std::enable_if_t<allocator_knows_ownership<U>::value>>
bool bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >::owns ( const void *  p) const
noexcept

Checks if p is owned by the underlying allocator.

Note
This function is only enabled if the underlying ExtendedAllocator supports it
Parameters
pthe pointer to check
Returns
true if p is owned by this allocator

◆ tracker()

template<typename ExtendedAllocator , typename MemoryTagger , typename MemoryTracker , typename BoundsChecker , typename BasicLockable >
const tracker_type& bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >::tracker ( ) const
noexcept

Accesses the tracker from the policy_allocator.

Returns
the tracker

◆ try_allocate()

template<typename ExtendedAllocator , typename MemoryTagger , typename MemoryTracker , typename BoundsChecker , typename BasicLockable >
void* bit::memory::policy_allocator< ExtendedAllocator, MemoryTagger, MemoryTracker, BoundsChecker, BasicLockable >::try_allocate ( std::size_t  size,
std::size_t  align 
)
noexcept

Attempts to allocate size bytes aligned to a boundary of align using the underlying allocator.

Returns
an allocated pointer on success, nullptr on failure

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