4#include "../Foundation/Internal/IGrowableBuffer.h"
5#include "../Memory/Segment.h"
15struct SegmentBuffer :
public SegmentTrivial<char>,
public SegmentSelfRelativePointer<char>
17 static constexpr bool IsArray =
false;
30 using Segment::Segment;
39 SmallBuffer(SegmentAllocator allocator = SegmentAllocator::Global) noexcept :
Buffer(N, allocator) {}
42 Buffer& operator=(
const Buffer& other)
noexcept {
return Buffer::operator=(other); }
43 Buffer& operator=(
Buffer&& other)
noexcept {
return Buffer::operator=(
move(other)); }
53 SmallBuffer(
int num, SegmentAllocator allocator) :
Buffer(N, allocator) { (void)num; }
60using BufferTL = detail::SegmentCustom<Buffer, Buffer, 0, SegmentAllocator::ThreadLocal>;
62using SmallBufferTL = detail::SegmentCustom<SmallBuffer<N>,
Buffer, N, SegmentAllocator::ThreadLocal>;
66struct SC_COMPILER_EXPORT
Buffer;
71struct SC_COMPILER_EXPORT GrowableBuffer<
Buffer> :
public IGrowableBuffer
74 GrowableBuffer(
Buffer& buffer)
noexcept;
75 ~GrowableBuffer()
noexcept;
76 static bool tryGrowTo(IGrowableBuffer&,
size_t newSize)
noexcept;
77 void finalize()
noexcept;
81struct SC_COMPILER_EXPORT GrowableBuffer<
SmallBuffer<N>> :
public IGrowableBuffer
84 GrowableBuffer(
Buffer& buffer) noexcept : IGrowableBuffer(&GrowableBuffer::tryGrowTo), buffer(buffer)
86 IGrowableBuffer::directAccess = {buffer.size(), buffer.capacity(), buffer.data()};
88 ~GrowableBuffer()
noexcept { finalize(); }
90 static bool tryGrowTo(IGrowableBuffer& gb,
size_t newSize)
noexcept
92 GrowableBuffer& self =
static_cast<GrowableBuffer&
>(gb);
93 const bool result = self.buffer.resizeWithoutInitializing(newSize);
94 self.directAccess = {self.buffer.size(), self.buffer.capacity(), self.buffer.data()};
97 void finalize()
noexcept { (void)buffer.resizeWithoutInitializing(IGrowableBuffer::directAccess.sizeInBytes); }
constexpr T && move(T &value)
Converts an lvalue to an rvalue reference.
Definition Compiler.h:257
unsigned long long uint64_t
Platform independent (8) bytes unsigned int.
Definition PrimitiveTypes.h:42
An heap allocated byte buffer that can optionally use an inline buffer.
Definition Buffer.h:29
A slice of contiguous memory, prefixed by and header containing size and capacity.
Definition Segment.h:113
A SC::Buffer with a dedicated custom inline buffer to avoid heap allocation.
Definition Buffer.h:38