gwnavgeneration/common/growingsmallbuffer.h Source File

growingsmallbuffer.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 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 // primary contact: GUAL - secondary contact: NOBODY
9 #ifndef GwNavGen_GrowingSmallBufferPool_H
10 #define GwNavGen_GrowingSmallBufferPool_H
11 
12 
15 
16 
17 namespace Kaim
18 {
19 
20 
21 class GrowingSmallBufferPool
22 {
23  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
24 public:
25  explicit GrowingSmallBufferPool(MemoryHeap* heap, KyUInt32 byteCountInChunk = 0);
26 
27  ~GrowingSmallBufferPool();
28 
29  KyUInt32 GetWordCount(KyInt32 byteCount);
30 
31  void* GetNewBuffer(KyUInt32 byteCount);
32 
33  void Clear();
34 
35  void Release();
36 
37  KyUInt32 ByteCountAllocated() const { return m_byteCountAllocated; }
38 
39 private:
40  KyUInt32 m_maxWordCountInChunk;
41 
42  KyArrayTLS_POD<KyUInt32*> m_chunks; // TODO use KyArray
43  KyUInt32 m_chunkCount;
44  KyUInt32 m_wordCountInLastChunk;
45 
46  KyArrayTLS_POD<KyUInt32*> m_oversizedBuffers; // TODO use KyArray
47 
48  KyUInt32 m_byteCountAllocated;
49 
50  MemoryHeap* m_heap;
51 };
52 
53 KY_INLINE KyUInt32 GrowingSmallBufferPool::GetWordCount(KyInt32 byteCount)
54 {
55  // warning: don't use (byteCount - 1) / sizeof(KyUInt32) + 1; because it performs the division in KyUInt32 !!
56  return (byteCount - 1) / (KyInt32)sizeof(KyUInt32) + 1;
57 }
58 
59 }
60 
61 
62 #endif
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36