4#include "../Foundation/Internal/IGrowableBuffer.h"
5#include "../Memory/Memory.h"
6#include "../Memory/Segment.h"
16struct SC_MEMORY_EXPORT SegmentBuffer :
public SegmentTrivial<char>,
public SegmentSelfRelativePointer<char>
18 static constexpr bool IsArray =
false;
31 using Segment::Segment;
40 SmallBuffer(SegmentAllocator allocator = SegmentAllocator::Global) noexcept :
Buffer(N, allocator) {}
43 Buffer& operator=(
const Buffer& other)
noexcept {
return Buffer::operator=(other); }
44 Buffer& operator=(
Buffer&& other)
noexcept {
return Buffer::operator=(
move(other)); }
54 SmallBuffer(
int num, SegmentAllocator allocator) :
Buffer(N, allocator) { (void)num; }
61using BufferTL = detail::SegmentCustom<Buffer, Buffer, 0, SegmentAllocator::ThreadLocal>;
63using SmallBufferTL = detail::SegmentCustom<SmallBuffer<N>,
Buffer, N, SegmentAllocator::ThreadLocal>;
67struct SC_MEMORY_EXPORT
Buffer;
72struct SC_MEMORY_EXPORT GrowableBuffer<
Buffer> :
public IGrowableBuffer
75 GrowableBuffer(
Buffer& buffer)
noexcept;
76 ~GrowableBuffer()
noexcept;
77 static bool tryGrowTo(IGrowableBuffer&,
size_t newSize)
noexcept;
78 void finalize()
noexcept;
82struct SC_MEMORY_EXPORT GrowableBuffer<
SmallBuffer<N>> :
public IGrowableBuffer
85 GrowableBuffer(
Buffer& buffer) noexcept : IGrowableBuffer(&GrowableBuffer::tryGrowTo), buffer(buffer)
87 IGrowableBuffer::directAccess = {buffer.size(), buffer.capacity(), buffer.data()};
89 ~GrowableBuffer()
noexcept { finalize(); }
91 static bool tryGrowTo(IGrowableBuffer& gb,
size_t newSize)
noexcept
93 GrowableBuffer& self =
static_cast<GrowableBuffer&
>(gb);
94 const bool result = self.buffer.resizeWithoutInitializing(newSize);
95 self.directAccess = {self.buffer.size(), self.buffer.capacity(), self.buffer.data()};
98 void finalize()
noexcept { (void)buffer.resizeWithoutInitializing(IGrowableBuffer::directAccess.sizeInBytes); }
constexpr T && move(T &value)
Converts an lvalue to an rvalue reference.
Definition Compiler.h:273
unsigned long long uint64_t
Platform independent (8) bytes unsigned int.
Definition PrimitiveTypes.h:33
An heap allocated byte buffer that can optionally use an inline buffer.
Definition Buffer.h:30
A slice of contiguous memory, prefixed by and header containing size and capacity.
Definition Segment.h:114
A SC::Buffer with a dedicated custom inline buffer to avoid heap allocation.
Definition Buffer.h:39