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> final :
public IGrowableBuffer
74 GrowableBuffer(
Buffer& buffer);
76 virtual bool tryGrowTo(
size_t newSize)
override;
80struct SC_COMPILER_EXPORT GrowableBuffer<
SmallBuffer<N>> final :
public IGrowableBuffer
83 GrowableBuffer(
Buffer& buffer) : buffer(buffer)
85 IGrowableBuffer::directAccess = {buffer.size(), buffer.capacity(), buffer.data()};
87 ~GrowableBuffer() { (void)buffer.resizeWithoutInitializing(IGrowableBuffer::directAccess.sizeInBytes); }
88 virtual bool tryGrowTo(
size_t newSize)
override
90 const bool result = buffer.resizeWithoutInitializing(newSize);
91 IGrowableBuffer::directAccess = {buffer.size(), buffer.capacity(), buffer.data()};
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