12#define BOOST_TEST_MODULE GenericTrackingBoundedAllocator
13#define BOOST_TEST_MAIN
14#define BOOST_TEST_DYN_LINK
15#include <boost/test/unit_test.hpp>
27 void* do_allocate(
size_t,
size_t)
final {
throw std::bad_alloc{}; }
28 void do_deallocate(
void*,
size_t,
size_t)
final {}
33 static inline int copiesBeforeFailure = -1;
34 ThrowingCopy() =
default;
35 ThrowingCopy(
const ThrowingCopy&)
37 if (copiesBeforeFailure == 0) {
38 throw std::runtime_error{
"copy"};
40 if (copiesBeforeFailure > 0) {
41 --copiesBeforeFailure;
44 ThrowingCopy& operator=(
const ThrowingCopy&) =
default;
51 void* held = pool.allocate(8);
55 pool.deallocate(held, 8);
63 BOOST_CHECK_THROW(
static_cast<void>(pool.allocate(16)), std::bad_alloc);
72 void*
first = pool.allocate(16);
75 const size_t previousPeak = pool.resetPeakMemory();
78 pool.setMaxMemory(24);
79 void* second = pool.allocate(8);
82 pool.deallocate(second, 8);
83 pool.deallocate(
first, 16);
87 pool.raisePeakMemory(24);
110 ThrowingCopy::copiesBeforeFailure = 1;
113 ThrowingCopy::copiesBeforeFailure = -1;
126 auto* storage =
values.data();
138 std::vector<BoundedVector<int>> nested;
140 for (
auto&
values : nested) {
146 for (
const auto&
values : nested) {
150 std::array<BoundedVector<int>, 2>
array;
Shared budgeted host allocation and bounded-vector utilities.
size_t getAllocationCount() const noexcept
size_t getThrowCount() const noexcept
size_t getUsedMemory() const noexcept
GLenum GLsizei GLsizei GLint * values
void clearResizeBoundedVector(bounded_vector< T > &vec, size_t sz, std::pmr::memory_resource *mr=nullptr, T def=T())
void resizeBoundedVector(BoundedVector< T > &vec, size_t sz, std::pmr::memory_resource *mr=nullptr)
void deepVectorClear(std::vector< T > &vec)
void clearResizeBoundedArray(std::array< bounded_vector< T >, S > &arr, size_t size, std::pmr::memory_resource *mr=nullptr, T def=T())
std::pmr::vector< T > BoundedVector
BOOST_AUTO_TEST_CASE(huge_request_cannot_wrap_past_budget)
VectorOfTObjectPtrs other
BOOST_CHECK_EQUAL(triggersD.size(), triggers.size())