gwnavruntime/querysystem/workingmemcontainers/workingmemcontainerbase.h Source File
Go to the documentation of this file.
19 class WorkingMemContainerBase
22 WorkingMemContainerBase() : m_workingMemory(nullptr), m_bufferIdx(BufferIndex_Invalid) {}
23 WorkingMemContainerBase(WorkingMemory* workingMemory) : m_workingMemory(nullptr), m_bufferIdx(BufferIndex_Invalid) { Init(workingMemory); }
24 ~WorkingMemContainerBase() { ReleaseBuffer(); }
26 KyResult Init(WorkingMemory* workingMemory)
30 BufferIndex bufferIdx = workingMemory->TakeUsageOfFirstUnusedBufferIdx();
32 if (bufferIdx == BufferIndex_Invalid)
35 m_workingMemory = workingMemory;
36 m_bufferIdx = bufferIdx;
38 if (workingMemory->GetBuffer(bufferIdx) ==
nullptr)
40 if (workingMemory->AllocBiggerBuffer(bufferIdx) ==
nullptr)
49 bool IsInitialized()
const {
return m_workingMemory !=
nullptr; }
51 void* GetBuffer()
const {
return m_workingMemory->GetBuffer(m_bufferIdx); }
52 KyUInt32 GetBufferSize()
const {
return m_workingMemory->GetBufferSize(m_bufferIdx); }
54 char* GetDataPtr()
const {
return (
char*)m_workingMemory->GetBuffer(m_bufferIdx); }
55 KyUInt32 GetCapacity()
const {
return m_workingMemory->GetBufferSize(m_bufferIdx); }
59 void* AllocBiggerBuffer(
KyUInt32 newMinByteSize = 0) {
return m_workingMemory->AllocBiggerBuffer(m_bufferIdx, newMinByteSize); }
64 void* oldBuffer = GetBuffer();
66 if (newSize <= GetBufferSize())
69 void* newBuffer = AllocBiggerBuffer(newSize);
70 if (newBuffer ==
nullptr)
73 memcpy(newBuffer, oldBuffer, oldSize);
75 #if defined(KY_BUILD_DEBUG)
76 memset(oldBuffer, 0xAB, oldSize);
79 ReleaseMemory(oldBuffer);
83 void ReleaseMemory(
void* memory) { m_workingMemory->ReleaseMemory(memory); }
88 if (m_workingMemory !=
nullptr)
90 m_workingMemory->ReleaseBuffer(m_bufferIdx);
92 m_workingMemory =
nullptr;
93 m_bufferIdx = BufferIndex_Invalid;
98 WorkingMemory* m_workingMemory;
99 BufferIndex m_bufferIdx;
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Navigation return code class.
Definition: types.h:108
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
#define KY_ERROR
use result == KY_ERROR to test for error
Definition: types.h:132