gwnavruntime/kernel/HeapPT/HeapPT_AllocBitSet2.h Source File

HeapPT_AllocBitSet2.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 
9 Filename : HeapPT_AllocBitSet2.h
10 Content : Bit-set based allocator, 2 bits per block.
11 
12 Created : 2009
13 Authors : Maxim Shemanarev
14 
15 **************************************************************************/
16 
17 #ifndef INC_KY_Kernel_HeapPT_AllocBitSet2_H
18 #define INC_KY_Kernel_HeapPT_AllocBitSet2_H
19 
22 
23 namespace Kaim { namespace HeapPT {
24 
25 //------------------------------------------------------------------------
26 class AllocBitSet2
27 {
28 public:
29  AllocBitSet2(UPInt minAlignShift);
30 
31  void Reset() { Bin.Reset(); }
32 
33  static UInt32* GetBitSet(const HeapSegment* seg)
34  {
35  return (UInt32*)(((UByte*)seg) + sizeof(HeapSegment));
36  }
37 
38  UPInt GetBitSetWords(UPInt dataSize) const
39  {
40  return BitSet2::GetBitSetSize(dataSize, MinAlignShift);
41  }
42 
43  UPInt GetBitSetBytes(UPInt dataSize) const
44  {
45  return GetBitSetWords(dataSize) * sizeof(UInt32);
46  }
47 
48  void InitSegment(HeapSegment* seg);
49  void ReleaseSegment(HeapSegment* seg);
50 
51  void* Alloc(UPInt size, HeapSegment** allocSeg);
52  void* Alloc(UPInt size, UPInt alignSize, HeapSegment** allocSeg);
53 
54  void Free(HeapSegment* seg, void* ptr);
55  void* ReallocInPlace(HeapSegment* seg, void* oldPtr,
56  UPInt newSize, UPInt* oldSize);
57 
58  UPInt GetUsableSize(const HeapSegment* seg, const void* ptr) const;
59  UPInt GetAlignShift(const HeapSegment* seg, const void* ptr, UPInt size) const;
60 
61  UPInt GetTotalFreeSpace() const
62  {
63  return Bin.GetTotalFreeSpace(MinAlignShift);
64  }
65 
66  void VisitMem(MemVisitor* visitor, MemVisitor::Category cat) const
67  {
68  Bin.VisitMem(visitor, MinAlignShift, cat);
69  }
70 
71  void VisitUnused(SegVisitor* visitor, unsigned cat) const
72  {
73  Bin.VisitUnused(visitor, MinAlignShift, cat);
74  }
75 
76  void CheckIntegrity() const
77  {
78  Bin.CheckIntegrity(MinAlignShift);
79  }
80 
81 private:
82  UPInt MinAlignShift;
83  UPInt MinAlignMask;
84  FreeBin Bin;
85 };
86 
87 }} // Kaim::Heap
88 
89 
90 #endif
Definition: gamekitcrowddispersion.h:20