gwnavruntime/kernel/HeapMH/HeapMH_AllocEngine.h Source File

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