gwnavruntime/kernel/HeapMH/HeapMH_MemoryHeap.h Source File

HeapMH_MemoryHeap.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 PublicHeader: Kernel
10 Filename : HeapMH_MemoryHeap.h
11 Content : Public memory heap class declaration, MagicHeader engine.
12 Created : October 1, 2008
13 Authors : Michael Antonov, Maxim Shemanarev
14 
15 **************************************************************************/
16 
17 #ifndef INC_KY_Kernel_HeapMH_MemoryHeap_H
18 #define INC_KY_Kernel_HeapMH_MemoryHeap_H
19 
21 
22 namespace Kaim {
23 
24 // *** Predeclarations
25 //------------------------------------------------------------------------
26 namespace HeapMH
27 {
28  class RootMH;
29  class AllocEngineMH;
30  class DebugStorageMH;
31  struct PageMH;
32  struct NodeMH;
33  struct PageInfoMH;
34 }
35 
36 // ***** MemoryHeap
37 //------------------------------------------------------------------------
38 class MemoryHeapMH : public MemoryHeap
39 {
40 private:
41  friend class HeapMH::RootMH;
42 
43  MemoryHeapMH(); // Explicit creation and destruction is prohibited
44  virtual ~MemoryHeapMH() {}
45 
46 public:
47 
48  // *** Operations with memory arenas
49  //
50  //--------------------------------------------------------------------
51  virtual void CreateArena(UPInt arena, SysAllocPaged* sysAlloc);
52  virtual void DestroyArena(UPInt arena);
53  virtual bool ArenaIsEmpty(UPInt arena);
54 
55  // *** Initialization
56  //
57  // Creates a nested child heap; The heap should be destroyed
58  // by calling release. If child heap creation failed due to
59  // out-of-memory condition, returns 0. If child heap creation
60  // is not supported a pointer to the same parent heap will be returned.
61  //--------------------------------------------------------------------
62  virtual MemoryHeap* CreateHeap(const char* name,
63  const HeapDesc& desc);
64 
65  // *** Service functions
66  //--------------------------------------------------------------------
67 
68  virtual void SetLimitHandler(LimitHandler* handler);
69  virtual void SetLimit(UPInt newLimit);
70  virtual void AddRef();
71  virtual void Release();
72 
73  // *** Allocation API
74  //--------------------------------------------------------------------
75  virtual void* Alloc(UPInt size, const AllocInfo* info = 0);
76  virtual void* Alloc(UPInt size, UPInt align, const AllocInfo* info = 0);
77  virtual void* Realloc(void* oldPtr, UPInt newSize);
78  virtual void Free(void* ptr);
79  virtual void* AllocAutoHeap(const void *thisPtr, UPInt size,
80  const AllocInfo* info = 0);
81 
82  virtual void* AllocAutoHeap(const void *thisPtr, UPInt size, UPInt align,
83  const AllocInfo* info = 0);
84 
85  virtual MemoryHeap* GetAllocHeap(const void *thisPtr);
86 
87  virtual UPInt GetUsableSize(const void* ptr);
88 
89 
90  virtual void* AllocSysDirect(UPInt size);
91  virtual void FreeSysDirect(void* ptr, UPInt size);
92 
93  // *** Statistics
94  //--------------------------------------------------------------------
95  virtual bool GetStats(StatBag* bag);
96  virtual UPInt GetFootprint() const;
97  virtual UPInt GetTotalFootprint() const;
98  virtual UPInt GetUsedSpace() const;
99  virtual UPInt GetTotalUsedSpace() const;
100  virtual void GetRootStats(RootStats* stats);
101  virtual void VisitMem(Heap::MemVisitor* visitor, unsigned flags);
102 
103  virtual void VisitRootSegments(Heap::SegVisitor* visitor);
104  virtual void VisitHeapSegments(Heap::SegVisitor* visitor) const;
105  virtual void SetTracer(HeapTracer* tracer);
106 
107 private:
108  //--------------------------------------------------------------------
109  virtual void destroyItself();
110  virtual void ultimateCheck();
111  virtual void releaseCachedMem();
112  virtual bool dumpMemoryLeaks();
113  virtual void checkIntegrity() const;
114  virtual void getUserDebugStats(RootStats* stats) const;
115 
116  void* allocMem(UPInt size, const AllocInfo* info);
117  void* allocMem(UPInt size, UPInt align, const AllocInfo* info);
118  void* allocMem(HeapMH::PageInfoMH* parentInfo, const void *thisPtr, UPInt size, const AllocInfo* info);
119  void* allocMem(HeapMH::PageInfoMH* parentInfo, const void *thisPtr, UPInt size, UPInt align, const AllocInfo* info);
120  void* reallocMem(HeapMH::PageMH* page, void* oldPtr, UPInt newSize);
121  void* reallocMem(HeapMH::NodeMH* node, void* oldPtr, UPInt newSize);
122 
123  void freeLocked(void* ptr);
124  void freeMem(HeapMH::PageMH* page, void* ptr);
125  void freeMem(HeapMH::NodeMH* node, void* ptr);
126 
127  //--------------------------------------------------------------------
128  HeapMH::AllocEngineMH* pEngine;
129  HeapMH::DebugStorageMH* pDebugStorage;
130 };
131 
132 } // Scaleform
133 
134 #endif
Definition: gamekitcrowddispersion.h:20