gwnavruntime/kernel/HeapPT/HeapPT_Bookkeeper.h Source File

HeapPT_Bookkeeper.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_Bookkeeper.h
10 Content : Bookkeeping allocator
11 Created : 2009
12 Authors : Maxim Shemanarev
13 
14 Notes : Internal allocator used to store bookkeeping information.
15 
16 **************************************************************************/
17 
18 #ifndef INC_KY_Kernel_HeapPT_Bookkeeper_H
19 #define INC_KY_Kernel_HeapPT_Bookkeeper_H
20 
25 
26 namespace Kaim { namespace HeapPT {
27 
28 using namespace Heap;
29 
30 // ***** Bookkeeper
31 //
32 // Internal allocator used to store bookkeeping information.
33 //------------------------------------------------------------------------
34 class Bookkeeper
35 {
36 public:
37  typedef List<HeapSegment> SegmentListType;
38 
39  Bookkeeper(SysAllocPaged* sysAlloc, UPInt granularity = Heap_PageSize);
40 
41  SysAllocPaged* GetSysAlloc() { return pSysAlloc; }
42 
43  void* Alloc(UPInt size);
44  void Free(void* ptr, UPInt size);
45 
46  void VisitMem(MemVisitor* visitor, unsigned flags) const;
47  void VisitSegments(SegVisitor* visitor) const;
48 
49  UPInt GetFootprint() const { return Footprint; }
50  UPInt GetUsedSpace() const { return Footprint - Allocator.GetTotalFreeSpace(); }
51 
52 private:
53  UPInt getHeaderSize(UPInt dataSize) const;
54  HeapSegment* allocSegment(UPInt size);
55  void freeSegment(HeapSegment* seg);
56 
57  SysAllocPaged* pSysAlloc;
58  UPInt Granularity;
59  SegmentListType SegmentList;
60  AllocBitSet1 Allocator;
61  UPInt Footprint;
62 };
63 
64 }} //Kaim::Heap
65 
66 #endif
Definition: gamekitcrowddispersion.h:20