gwnavgeneration/common/growingsmallbuffer.h Source File

growingsmallbuffer.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 #pragma once
9 
10 
13 
14 
15 namespace Kaim
16 {
17 
18 
19 class GrowingSmallBufferPool
20 {
21  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
22 public:
23  explicit GrowingSmallBufferPool(MemoryHeap* heap, KyUInt32 byteCountInChunk = 0);
24 
25  ~GrowingSmallBufferPool();
26 
27  KyUInt32 GetWordCount(KyInt32 byteCount);
28 
29  void* GetNewBuffer(KyUInt32 byteCount);
30 
31  void Clear();
32 
33  void Release();
34 
35  KyUInt32 ByteCountAllocated() const { return m_byteCountAllocated; }
36 
37 private:
38  KyUInt32 m_maxWordCountInChunk;
39 
40  KyArrayTLS_POD<KyUInt32*> m_chunks; // TODO use KyArray
41  KyUInt32 m_chunkCount;
42  KyUInt32 m_wordCountInLastChunk;
43 
44  KyArrayTLS_POD<KyUInt32*> m_oversizedBuffers; // TODO use KyArray
45 
46  KyUInt32 m_byteCountAllocated;
47 
48  MemoryHeap* m_heap;
49 };
50 
51 KY_INLINE KyUInt32 GrowingSmallBufferPool::GetWordCount(KyInt32 byteCount)
52 {
53  // warning: don't use (byteCount - 1) / sizeof(KyUInt32) + 1; because it performs the division in KyUInt32 !!
54  return (byteCount - 1) / (KyInt32)sizeof(KyUInt32) + 1;
55 }
56 
57 }
58 
59 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::int32_t KyInt32
int32_t
Definition: types.h:24