Sequoia
|
Somewhat similar to std::allocator but logs (de)allocations via an counter which is shared upon copying. More...
#include <AllocationTestUtilities.hpp>
Classes | |
struct | rebind |
Public Member Functions | |
shared_counting_allocator (const shared_counting_allocator &)=default | |
shared_counting_allocator & | operator= (const shared_counting_allocator &)=default |
T * | allocate (std::size_t n) |
void | deallocate (T *p, std::size_t n) |
int | allocs () const noexcept |
int | deallocs () const noexcept |
Friends | |
bool | operator== (const shared_counting_allocator &, const shared_counting_allocator &) noexcept=default |
Somewhat similar to std::allocator but logs (de)allocations via an counter which is shared upon copying.
A fundamental ingredient of the allocation testing framework is the capactity to count the number of allocations which have occured before/after some operation and to compare the difference to a prediction. Experimentation has (tentatively) suggested that the most robust way to do this is for copies of an allocator to share a counter. The benefit of this is that the framework is sensitive to copies of the allocator being taken between the measurement points. For example, the framework can (and has!) detected a typo in an overload of operator== in which one of the arguments was accidentally taken by value, leading to unexpected allocations.
There is also a more subtle difference to std:allocator<T>. Whereas the latter allows construction from std::allocator<U> this possibility is excluded to ensure that constructors of classes taking multiple allocators do not confuse them internally.
In addition to taking the usual T as a template parameter, the class template accepts three bools which control whether or not the allocator is propapaged when the associated container is copied, moved or swapped.