gwnavruntime/kernel/HeapPT/HeapPT_Starter.h Source File

HeapPT_Starter.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_Starter.h
10 Content : Starter allocator
11 Created : 2009
12 Authors : Maxim Shemanarev
13 
14 Notes : Internal allocator used for the initial bootstrapping.
15  It allocates/frees the page mapping arrays.
16 
17 **************************************************************************/
18 
19 #ifndef INC_KY_Kernel_Heap_Starter_H
20 #define INC_KY_Kernel_Heap_Starter_H
21 
23 
24 namespace Kaim { namespace HeapPT {
25 
26 // ***** Starter
27 //
28 // Internal allocator used for the initial bootstrapping.
29 // It allocates/frees the page mapping arrays, but can also be used
30 // as a general purpose allocator that requires the allocation size
31 // when freeing memory.
32 //
33 // The starter is just optimized for pages of the same size. On 64-bit
34 // platforms the pages can have different sizes, but definitely there
35 // will not be a great variety of sizes. Most of the requests will be
36 // of the same size, only few of them will have a bigger size.
37 //
38 // On 32-bit platforms, the detailed situation looks like this:
39 // Assume HeaderPageSize=4k, Granularity=16K, and allocation requests
40 // for exactly 1K PageTables.
41 // One PageTable (1K) can serve 1MB, one header can serve 16 PageTables,
42 // that is, 16 MB. One header page can keep information about 204 headers,
43 // that is, all in all it can serve space of 3264 MB. Only after exceeding
44 // it (if anything is left available) the starter has to allocate the second
45 // header page to serve the rest of physically available 4 GB of address
46 // space (not to mention on 32-bit WinXP/Vista only 3GB is available).
47 //
48 // On 64-bit platforms, the situation is heavier, but still, remains
49 // quite acceptable. You probably have to increase the "HeaderPageSize"
50 // and "Granularity". In 64-bit case HeaderPageSize=8K and Granularity=32K
51 // will serve the requests perfectly.
52 //
53 // The only restriction is: HeaderPageSize and Granularity cannot be
54 // less than Heap_PageSize.
55 //------------------------------------------------------------------------
56 class Starter
57 {
58 public:
59  Starter(SysAllocPaged* sysAlloc,
60  UPInt granularity = 4*Heap_PageSize,
61  UPInt headerPageSize = 1*Heap_PageSize);
62 
63  SysAllocPaged* GetSysAlloc() { return Allocator.GetSysAlloc(); }
64 
65  void* Alloc(UPInt size, UPInt alignSize);
66  void Free(void* ptr, UPInt size, UPInt alignSize); // Size is required!
67 
68  void VisitMem(MemVisitor* visitor) const;
69  void VisitSegments(class SegVisitor* visitor) const;
70 
71  UPInt GetFootprint() const { return Allocator.GetFootprint(); }
72  UPInt GetUsedSpace() const { return Allocator.GetUsedSpace(); }
73 
74 private:
75  Granulator Allocator;
76 };
77 
78 }} // Kaim::Heap
79 
80 #endif
Definition: gamekitcrowddispersion.h:20