Go to the documentation of this file.
34 #include "../../Primitives/interface/BasicTypes.h"
35 #include "../../Primitives/interface/MemoryAllocator.h"
36 #include "../../Platforms/Basic/interface/DebugUtilities.hpp"
54 m_pBuffer {Pool.m_pBuffer },
55 m_pCurrPtr {Pool.m_pCurrPtr },
56 m_ReservedSize{Pool.m_ReservedSize},
57 m_pAllocator {Pool.m_pAllocator }
60 Pool.m_pBuffer =
nullptr;
61 Pool.m_pCurrPtr =
nullptr;
62 Pool.m_ReservedSize = 0;
63 Pool.m_pAllocator =
nullptr;
75 VERIFY(m_ReservedSize == 0,
"Pool is already initialized");
76 m_pAllocator = &Allocator;
77 m_ReservedSize = Size;
78 if (m_ReservedSize != 0)
80 m_pBuffer =
reinterpret_cast<Char*
>(m_pAllocator->
Allocate(m_ReservedSize,
"Memory for string pool", __FILE__, __LINE__));
82 m_pCurrPtr = m_pBuffer;
87 if (m_pBuffer !=
nullptr && m_pAllocator !=
nullptr)
89 m_pAllocator->
Free(m_pBuffer);
95 m_pAllocator =
nullptr;
100 return str !=
nullptr ? strlen(str) + 1 : 0;
105 return str.length() + 1;
110 VERIFY(m_ReservedSize == 0,
"Pool is already initialized");
111 m_ReservedSize = Size;
113 m_pCurrPtr = m_pBuffer;
118 VERIFY(m_pCurrPtr +
Length <= m_pBuffer + m_ReservedSize,
"Not enough space in the buffer");
119 auto* Ptr = m_pCurrPtr;
126 auto len = Str.length();
130 memcpy(str, Str.data(), len *
sizeof(str[0]));
141 auto* Ptr = m_pCurrPtr;
142 while (*Str != 0 && m_pCurrPtr < m_pBuffer + m_ReservedSize)
144 *(m_pCurrPtr++) = *(Str++);
146 if (m_pCurrPtr < m_pBuffer + m_ReservedSize)
149 UNEXPECTED(
"Not enough space reserved in the string pool");
156 VERIFY(m_pCurrPtr <= m_pBuffer + m_ReservedSize,
"Buffer overflow");
157 return m_ReservedSize - (m_pCurrPtr - m_pBuffer);
161 VERIFY(m_pCurrPtr <= m_pBuffer + m_ReservedSize,
"Buffer overflow");
162 return m_pCurrPtr - m_pBuffer;
166 return m_ReservedSize;
170 Char* m_pBuffer =
nullptr;
171 Char* m_pCurrPtr =
nullptr;
172 size_t m_ReservedSize = 0;
char Char
Definition: BasicTypes.h:64
void Clear()
Definition: StringPool.hpp:85
StringPool & operator=(const StringPool &)=delete
size_t GetRemainingSize() const
Definition: StringPool.hpp:154
void AssignMemory(Char *pBuffer, size_t Size)
Definition: StringPool.hpp:108
Uint32 Length
Definition: DXBCUtils.cpp:59
#define UNEXPECTED(...)
Definition: DebugUtilities.hpp:77
Char * CopyString(const char *Str)
Definition: StringPool.hpp:136
Char * CopyString(const String &Str)
Definition: StringPool.hpp:124
StringPool(StringPool &&Pool)
Definition: StringPool.hpp:52
static size_t GetRequiredReserveSize(const std::string &str)
Definition: StringPool.hpp:103
~StringPool()
Definition: StringPool.hpp:66
StringPool()
Definition: StringPool.hpp:45
size_t GetUsedSize() const
Definition: StringPool.hpp:159
Base interface for a raw memory allocator.
Definition: MemoryAllocator.h:41
Char * Allocate(size_t Length)
Definition: StringPool.hpp:116
std::basic_string< Char > String
String variable.
Definition: BasicTypes.h:66
void Reserve(size_t Size, IMemoryAllocator &Allocator)
Definition: StringPool.hpp:71
#define VERIFY(...)
Definition: DebugUtilities.hpp:76
Implementation of a simple fixed-size string pool.
Definition: StringPool.hpp:42
virtual void Free(void *Ptr)=0
Releases memory.
virtual void * Allocate(size_t Size, const Char *dbgDescription, const char *dbgFileName, const Int32 dbgLineNumber)=0
Allocates block of memory.
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
static size_t GetRequiredReserveSize(const char *str)
Definition: StringPool.hpp:98
size_t GetReservedSize() const
Definition: StringPool.hpp:164