20 : nextSize(initialSize)
22 assert(initialSize != 0);
27 , available(bufferSize)
28 , nextSize(2 * bufferSize)
30 assert(buffer || bufferSize == 0);
42 void* next = *
static_cast<void**
>(p);
48 [[nodiscard]]
void*
allocate(
size_t bytes,
size_t alignment)
50 assert(alignment <=
alignof(max_align_t));
52 if (bytes == 0) bytes = 1;
53 void* p = std::align(alignment, bytes, current, available);
58 current =
static_cast<char*
>(current) + bytes;
64 void newBuffer(
size_t bytes)
66 size_t n = std::max(nextSize, bytes);
67 void* newBuf = malloc(n +
sizeof(
void*));
69 throw std::bad_alloc();
72 auto** p =
static_cast<void**
>(newBuf);
75 current =
static_cast<void*
>(&p[1]);
82 void* current =
nullptr;
84 size_t nextSize = 1024;
monotonic_allocator(const monotonic_allocator &)=delete
monotonic_allocator()=default
monotonic_allocator(void *buffer, size_t bufferSize)
monotonic_allocator & operator=(monotonic_allocator &&)=delete
monotonic_allocator(size_t initialSize)
monotonic_allocator(monotonic_allocator &&)=delete
void * allocate(size_t bytes, size_t alignment)
monotonic_allocator & operator=(const monotonic_allocator &)=delete