20 : nextSize(initialSize)
22 assert(initialSize != 0);
27 , available(bufferSize)
28 , nextSize(2 * bufferSize)
30 assert(buffer || bufferSize == 0);
40 void* next = *
static_cast<void**
>(p);
46 [[nodiscard]]
void*
allocate(
size_t bytes,
size_t alignment)
48 assert(alignment <=
alignof(max_align_t));
50 if (bytes == 0) bytes = 1;
51 void* p = std::align(alignment, bytes, current, available);
56 current =
static_cast<char*
>(current) + bytes;
62 void newBuffer(
size_t bytes)
64 size_t n =
std::max(nextSize, bytes);
65 void* newBuf = malloc(n +
sizeof(
void*));
67 throw std::bad_alloc();
70 void** p =
static_cast<void**
>(newBuf);
73 current =
static_cast<void*
>(&p[1]);
80 void* current =
nullptr;
82 size_t nextSize = 1024;
monotonic_allocator(const monotonic_allocator &)=delete
monotonic_allocator()=default
monotonic_allocator(void *buffer, size_t bufferSize)
monotonic_allocator(size_t initialSize)
void * allocate(size_t bytes, size_t alignment)
monotonic_allocator & operator=(const monotonic_allocator &)=delete
constexpr vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)