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

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

#include <wpi/memory/tracking.hpp>

Public Types

using allocator_type = typename allocator_traits<RawAllocator>::allocator_type
 
using tracker = Tracker
 
using is_stateful
 

Public Member Functions

 ~tracked_allocator () noexcept
 
void * allocate_node (std::size_t size, std::size_t alignment)
 
void * try_allocate_node (std::size_t size, std::size_t alignment) noexcept
 
void * allocate_array (std::size_t count, std::size_t size, std::size_t alignment)
 
void * try_allocate_array (std::size_t count, std::size_t size, std::size_t alignment) noexcept
 
void deallocate_node (void *ptr, std::size_t size, std::size_t alignment) noexcept
 
bool try_deallocate_node (void *ptr, std::size_t size, std::size_t alignment) noexcept
 
void deallocate_array (void *ptr, std::size_t count, std::size_t size, std::size_t alignment) noexcept
 
bool try_deallocate_array (void *ptr, std::size_t count, std::size_t size, std::size_t alignment) noexcept
 
 tracked_allocator (tracker t={}) noexcept
 
 tracked_allocator (tracker t, allocator_type &&allocator) noexcept
 
 tracked_allocator (tracked_allocator &&other) noexcept
 
tracked_allocatoroperator= (tracked_allocator &&other) noexcept
 
std::size_t max_node_size () const
 
std::size_t max_array_size () const
 
std::size_t max_alignment () const
 
allocator_typeget_allocator () noexcept
 
const allocator_typeget_allocator () const noexcept
 
trackerget_tracker () noexcept
 
const trackerget_tracker () const noexcept
 

Related Symbols

(Note that these are not member symbols.)

template<class Tracker , class RawAllocator >
auto make_tracked_allocator (Tracker t, RawAllocator &&alloc) -> tracked_allocator< Tracker, typename std::decay< RawAllocator >::type >
 

Detailed Description

template<class Tracker, class RawAllocator>
class wpi::memory::tracked_allocator< Tracker, RawAllocator >

A RawAllocator adapter that tracks another allocator using a tracker.

It wraps another RawAllocator and calls the tracker function before forwarding to it. The class can then be used anywhere a RawAllocator is required and the memory usage will be tracked.
If the RawAllocator uses deeply_tracked_block_allocator as BlockAllocator, it will also track growth and shrinking of the allocator.

Member Typedef Documentation

◆ allocator_type

template<class Tracker , class RawAllocator >
using wpi::memory::tracked_allocator< Tracker, RawAllocator >::allocator_type = typename allocator_traits<RawAllocator>::allocator_type

◆ is_stateful

template<class Tracker , class RawAllocator >
using wpi::memory::tracked_allocator< Tracker, RawAllocator >::is_stateful
Initial value:
std::integral_constant<bool, traits::is_stateful::value
|| !std::is_empty<Tracker>::value>

◆ tracker

template<class Tracker , class RawAllocator >
using wpi::memory::tracked_allocator< Tracker, RawAllocator >::tracker = Tracker

Constructor & Destructor Documentation

◆ tracked_allocator() [1/3]

template<class Tracker , class RawAllocator >
wpi::memory::tracked_allocator< Tracker, RawAllocator >::tracked_allocator ( tracker t = {})
inlineexplicitnoexcept
Effects:
Creates it by giving it a tracker and the tracked RawAllocator. It will embed both objects.
Note
This will never call the Tracker::on_allocator_growth() function.

◆ tracked_allocator() [2/3]

template<class Tracker , class RawAllocator >
wpi::memory::tracked_allocator< Tracker, RawAllocator >::tracked_allocator ( tracker t,
allocator_type && allocator )
inlinenoexcept

◆ ~tracked_allocator()

template<class Tracker , class RawAllocator >
wpi::memory::tracked_allocator< Tracker, RawAllocator >::~tracked_allocator ( )
inlinenoexcept
Effects:
Destroys both tracker and allocator.
Note
This will never call the Tracker::on_allocator_shrinking() function.

◆ tracked_allocator() [3/3]

template<class Tracker , class RawAllocator >
wpi::memory::tracked_allocator< Tracker, RawAllocator >::tracked_allocator ( tracked_allocator< Tracker, RawAllocator > && other)
inlinenoexcept
Effects:
Moving moves both the tracker and the allocator.

Member Function Documentation

◆ allocate_array()

template<class Tracker , class RawAllocator >
void * wpi::memory::tracked_allocator< Tracker, RawAllocator >::allocate_array ( std::size_t count,
std::size_t size,
std::size_t alignment )
inline
Effects:
Calls Tracker::on_array_allocation() and forwards to the allocator. If a growth occurs and the allocator is deeply tracked, also calls Tracker::on_allocator_growth().
Returns:
The result of allocate_array()

◆ allocate_node()

template<class Tracker , class RawAllocator >
void * wpi::memory::tracked_allocator< Tracker, RawAllocator >::allocate_node ( std::size_t size,
std::size_t alignment )
inline
Effects:
Calls Tracker::on_node_allocation() and forwards to the allocator. If a growth occurs and the allocator is deeply tracked, also calls Tracker::on_allocator_growth().
Returns:
The result of allocate_node()

◆ deallocate_array()

template<class Tracker , class RawAllocator >
void wpi::memory::tracked_allocator< Tracker, RawAllocator >::deallocate_array ( void * ptr,
std::size_t count,
std::size_t size,
std::size_t alignment )
inlinenoexcept
Effects:
Calls Tracker::on_array_deallocation() and forwards to the allocator's deallocate_array(). If shrinking occurs and the allocator is deeply tracked, also calls Tracker::on_allocator_shrinking().

◆ deallocate_node()

template<class Tracker , class RawAllocator >
void wpi::memory::tracked_allocator< Tracker, RawAllocator >::deallocate_node ( void * ptr,
std::size_t size,
std::size_t alignment )
inlinenoexcept
Effects:
Calls Tracker::on_node_deallocation() and forwards to the allocator's deallocate_node(). If shrinking occurs and the allocator is deeply tracked, also calls Tracker::on_allocator_shrinking().

◆ get_allocator() [1/2]

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

◆ get_allocator() [2/2]

template<class Tracker , class RawAllocator >
allocator_type & wpi::memory::tracked_allocator< Tracker, RawAllocator >::get_allocator ( )
inlinenoexcept
Returns:
A (const) reference to the wrapped allocator.

◆ get_tracker() [1/2]

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

◆ get_tracker() [2/2]

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

◆ max_alignment()

template<class Tracker , class RawAllocator >
std::size_t wpi::memory::tracked_allocator< Tracker, RawAllocator >::max_alignment ( ) const
inline

◆ max_array_size()

template<class Tracker , class RawAllocator >
std::size_t wpi::memory::tracked_allocator< Tracker, RawAllocator >::max_array_size ( ) const
inline

◆ max_node_size()

template<class Tracker , class RawAllocator >
std::size_t wpi::memory::tracked_allocator< Tracker, RawAllocator >::max_node_size ( ) const
inline
Returns:
The result of the corresponding function on the wrapped allocator.

◆ operator=()

template<class Tracker , class RawAllocator >
tracked_allocator & wpi::memory::tracked_allocator< Tracker, RawAllocator >::operator= ( tracked_allocator< Tracker, RawAllocator > && other)
inlinenoexcept

◆ try_allocate_array()

template<class Tracker , class RawAllocator >
void * wpi::memory::tracked_allocator< Tracker, RawAllocator >::try_allocate_array ( std::size_t count,
std::size_t size,
std::size_t alignment )
inlinenoexcept
Effects:
Calls the composable array allocation function. If allocation was succesful, also calls Tracker::on_array_allocation().
Returns:
The result of try_allocate_array().

◆ try_allocate_node()

template<class Tracker , class RawAllocator >
void * wpi::memory::tracked_allocator< Tracker, RawAllocator >::try_allocate_node ( std::size_t size,
std::size_t alignment )
inlinenoexcept
Effects:
Calls the composable node allocation function. If allocation was successful, also calls Tracker::on_node_allocation().
Returns:
The result of try_allocate_node().

◆ try_deallocate_array()

template<class Tracker , class RawAllocator >
bool wpi::memory::tracked_allocator< Tracker, RawAllocator >::try_deallocate_array ( void * ptr,
std::size_t count,
std::size_t size,
std::size_t alignment )
inlinenoexcept
Effects:
Calls the composable array deallocation function. If it was succesful, also calls Tracker::on_array_deallocation().
Returns:
The result of try_deallocate_array().

◆ try_deallocate_node()

template<class Tracker , class RawAllocator >
bool wpi::memory::tracked_allocator< Tracker, RawAllocator >::try_deallocate_node ( void * ptr,
std::size_t size,
std::size_t alignment )
inlinenoexcept
Effects:
Calls the composable node deallocation function. If it was succesful, also calls Tracker::on_node_deallocation().
Returns:
The result of try_deallocate_node().

Friends And Related Symbol Documentation

◆ make_tracked_allocator()

template<class Tracker , class RawAllocator >
auto make_tracked_allocator ( Tracker t,
RawAllocator && alloc ) -> tracked_allocator<Tracker, typename std::decay<RawAllocator>::type>
related
Effects:
Takes a RawAllocator and wraps it with a tracker.
Returns:
A tracked_allocator with the corresponding parameters forwarded to the constructor.

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