gwnavruntime/kernel/HeapMH/HeapMH_AllocEngine.h Source File

HeapMH_AllocEngine.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 : HeapMH_AllocEngine.h
10 Content : The main allocation engine
11  :
12 Created : 2009
13 Authors : Maxim Shemanarev
14 
15 **************************************************************************/
16 
17 #ifndef INC_KY_Kernel_HeapMH_AllocEngine_H
18 #define INC_KY_Kernel_HeapMH_AllocEngine_H
19 
23 
24 namespace Kaim { namespace HeapMH {
25 
26 //------------------------------------------------------------------------
27 class AllocEngineMH
28 {
29  typedef List<PageMH> PageListType;
30 public:
31  AllocEngineMH(SysAlloc* sysAlloc,
32  MemoryHeapMH* heap,
33  UPInt minAlignSize=16,
34  UPInt limit=0);
35  ~AllocEngineMH();
36 
37  bool IsValid() const { return true; }
38 
39  void FreeAll();
40 
41  UPInt SetLimit(UPInt lim) { return Limit = lim; }
42  void SetLimitHandler(void* handler) { pLimHandler = handler; }
43 
44  void* Alloc(UPInt size, PageInfoMH* info);
45  void* Alloc(UPInt size, UPInt alignSize, PageInfoMH* info);
46 
47  void* ReallocInPage(PageMH* page, void* oldPtr, UPInt newSize, PageInfoMH* newInfo);
48  void* ReallocInNode(NodeMH* node, void* oldPtr, UPInt newSize, PageInfoMH* newInfo);
49  void* ReallocGeneral(PageMH* page, void* oldPtr, UPInt newSize, PageInfoMH* newInfo);
50  void* Realloc(void* oldPtr, UPInt newSize);
51  void Free(PageMH* page, void* ptr);
52  void Free(NodeMH* node, void* ptr);
53  void Free(void* ptr);
54 
55  void GetPageInfo(PageMH* page, PageInfoMH* info) const;
56  void GetPageInfo(NodeMH* node, PageInfoMH* info) const;
57  void GetPageInfoWithSize(PageMH* page, const void* ptr, PageInfoMH* info) const;
58  void GetPageInfoWithSize(NodeMH* node, const void* ptr, PageInfoMH* info) const;
59 
60  UPInt GetFootprint() const { return Footprint; }
61  UPInt GetUsedSpace() const { return UsedSpace; }
62 
63  UPInt GetUsableSize(void* ptr);
64 
65 private:
66  PageMH* allocPage(bool* limHandlerOK);
67  void* allocDirect(UPInt size, UPInt alignSize, bool* limHandlerOK, PageInfoMH* info);
68  void freePage(PageMH* page);
69 
70  void* allocFromPage(UPInt size, PageInfoMH* info);
71  void* allocFromPage(UPInt size, UPInt alignSize, PageInfoMH* info);
72 
73  SysAlloc* pSysAlloc;
74  MemoryHeapMH* pHeap;
75  UPInt MinAlignSize;
76  AllocBitSet2MH Allocator;
77  PageListType Pages;
78  UPInt Footprint;
79  UPInt UsedSpace;
80  UPInt Limit;
81  void* pLimHandler;
82  UPInt UseCount;
83 };
84 
85 }} // Kaim::HeapMH
86 
87 #endif
88 
Definition: gamekitcrowddispersion.h:20