37 TOutputBuffer() =
default;
38 TOutputBuffer(
const TOutputBuffer&) =
delete;
39 TOutputBuffer& operator=(
const TOutputBuffer&) =
delete;
43 : Ptr(std::move(other.Ptr))
44 , Cap(std::exchange(other.Cap, 0))
48 TOutputBuffer&
operator=(TOutputBuffer&& other)
noexcept {
50 Ptr = std::move(other.Ptr);
51 Cap = std::exchange(other.Cap, 0);
69 if (size > Cap) [[unlikely]] {
75 void Swap(TOutputBuffer& other)
noexcept {
77 std::swap(Cap, other.Cap);
82 void operator()(
char* p)
const {
87 void Grow(
size_t used,
size_t size) {
90 std::unique_ptr<char, TFree> block(
static_cast<char*
>(std::malloc(cap)));
92 throw std::bad_alloc();
95 std::memcpy(block.get(), Ptr.get(), used);
97 Ptr = std::move(block);
100 char* block =
static_cast<char*
>(std::realloc(Ptr.get(), cap));
102 throw std::bad_alloc();
110 std::unique_ptr<char, TFree> Ptr;
121inline void PoisonAcquired([[maybe_unused]] std::span<char> range) {
123 if (!range.empty()) {
124 std::memset(range.data(), 0xA5, range.size());
TOutputBuffer & operator=(TOutputBuffer &&other) noexcept
Frees the block of this and takes the block of other, which is left empty.
Definition output_buffer.hpp:48
TOutputBuffer(TOutputBuffer &&other) noexcept
Takes the block; other is left empty.
Definition output_buffer.hpp:42
void Swap(TOutputBuffer &other) noexcept
Exchanges the blocks of the two buffers.
Definition output_buffer.hpp:75
static constexpr size_t MinCapacity
The smallest block Reserve allocates: small frames do not cause a chain of tiny reallocations.
Definition output_buffer.hpp:30
size_t Capacity() const
The size of the block in bytes.
Definition output_buffer.hpp:62
static constexpr size_t GrowthFactor
A block grows to this many times its size at least: the total copy stays proportional to the final si...
Definition output_buffer.hpp:32
static constexpr size_t StaleRatio
Definition output_buffer.hpp:35
void Reserve(size_t used, size_t size)
Definition output_buffer.hpp:68
char * Data()
The start of the block, null while the capacity is 0. Valid until the next Reserve or Swap.
Definition output_buffer.hpp:57