WPILibC++ 2025.1.1
Loading...
Searching...
No Matches
wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator > Class Template Reference

A BlockAllocator adapter that tracks another allocator using a tracker. More...

#include <wpi/memory/tracking.hpp>

Public Types

using allocator_type = make_block_allocator_t<BlockOrRawAllocator>
 
using tracker = Tracker
 

Public Member Functions

template<typename... Args>
 tracked_block_allocator (std::size_t block_size, tracker t, Args &&... args)
 
memory_block allocate_block ()
 
void deallocate_block (memory_block block) noexcept
 
std::size_t next_block_size () const noexcept
 
 tracked_block_allocator (tracker t={}) noexcept
 
 tracked_block_allocator (tracker t, allocator_type &&alloc) noexcept
 
allocator_typeget_allocator () noexcept
 
const allocator_typeget_allocator () const noexcept
 
trackerget_tracker () noexcept
 
const trackerget_tracker () const noexcept
 

Detailed Description

template<class Tracker, class BlockOrRawAllocator>
class wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator >

A BlockAllocator adapter that tracks another allocator using a tracker.

It wraps another BlockAllocator and calls the tracker function before forwarding to it. The class can then be used anywhere a BlockAllocator is required and the memory usage will be tracked.
It will only call the on_allocator_growth() and on_allocator_shrinking() tracking functions, since a BlockAllocator is normally used inside higher allocators only.

Member Typedef Documentation

◆ allocator_type

template<class Tracker , class BlockOrRawAllocator >
using wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator >::allocator_type = make_block_allocator_t<BlockOrRawAllocator>

◆ tracker

template<class Tracker , class BlockOrRawAllocator >
using wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator >::tracker = Tracker

Constructor & Destructor Documentation

◆ tracked_block_allocator() [1/3]

template<class Tracker , class BlockOrRawAllocator >
wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator >::tracked_block_allocator ( tracker t = {})
inlineexplicitnoexcept
Effects:
Creates it by giving it a tracker and the tracked RawAllocator. It will embed both objects.

◆ tracked_block_allocator() [2/3]

template<class Tracker , class BlockOrRawAllocator >
wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator >::tracked_block_allocator ( tracker t,
allocator_type && alloc )
inlinenoexcept

◆ tracked_block_allocator() [3/3]

template<class Tracker , class BlockOrRawAllocator >
template<typename... Args>
wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator >::tracked_block_allocator ( std::size_t block_size,
tracker t,
Args &&... args )
inline
Effects:
Creates it in the form required by the concept. The allocator will be constructed using block_size and args.

Member Function Documentation

◆ allocate_block()

template<class Tracker , class BlockOrRawAllocator >
memory_block wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator >::allocate_block ( )
inline
Effects:
Calls Tracker::on_allocator_growth() after forwarding to the allocator.
Returns:
The block as the returned by the allocator.

◆ deallocate_block()

template<class Tracker , class BlockOrRawAllocator >
void wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator >::deallocate_block ( memory_block block)
inlinenoexcept
Effects:
Calls Tracker::on_allocator_shrinking() and forwards to the allocator.

◆ get_allocator() [1/2]

template<class Tracker , class BlockOrRawAllocator >
const allocator_type & wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator >::get_allocator ( ) const
inlinenoexcept

◆ get_allocator() [2/2]

template<class Tracker , class BlockOrRawAllocator >
allocator_type & wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator >::get_allocator ( )
inlinenoexcept
Returns:
A (const) reference to the used allocator.

◆ get_tracker() [1/2]

template<class Tracker , class BlockOrRawAllocator >
const tracker & wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator >::get_tracker ( ) const
inlinenoexcept

◆ get_tracker() [2/2]

template<class Tracker , class BlockOrRawAllocator >
tracker & wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator >::get_tracker ( )
inlinenoexcept
Returns:
A (const) reference to the tracker.

◆ next_block_size()

template<class Tracker , class BlockOrRawAllocator >
std::size_t wpi::memory::tracked_block_allocator< Tracker, BlockOrRawAllocator >::next_block_size ( ) const
inlinenoexcept
Returns:
The next block size as returned by the allocator.

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