27#ifndef ALLOCATOR_POLICIES
28#define ALLOCATOR_POLICIES
43template<
size_t increment = g_PageSize>
48 return oldSize + increment;
62template<
size_t multiplier = 21,
size_t divisor = 16>
67 const size_t product = oldSize * multiplier;
72 ASSERT(product >= oldSize);
74 return product / divisor;
108template<
class Allocator = Allocator_Aligned<> >
154template<
class Allocator = Allocator_Heap,
class GrowthPolicy = Growth_Exponential<> >
182 return std::numeric_limits<size_t>::max();
187 size_t newCapacity = std::max(requiredCapacity, GrowthPolicy()(
capacity));
188 void* newStorage =
allocator.allocate(newCapacity);
194 allocator.deallocate(newStorage, newCapacity);
208template<
class Allocator = Allocator_AddressSpace<>,
class GrowthPolicy = Growth_Exponential<2,1> >
242 size_t newCapacity = std::max(requiredCapacity, GrowthPolicy()(
capacity));
246 newCapacity = Align<g_PageSize>(newCapacity);
267template<
class Allocator = Allocator_AddressSpace<> >
319template<
class Storage>
322 size_t newEnd = end + size;
325 if(!storage.
Expand(newEnd))
330 return storage.
Address() + newEnd;
336template<
template<
class Storage>
class Functor>
339 Functor<Storage_Fixed<Allocator_Heap> >()();
340 Functor<Storage_Fixed<Allocator_Aligned<> > >()();
342 Functor<Storage_Reallocate<Allocator_Heap, Growth_Linear<> > >()();
343 Functor<Storage_Reallocate<Allocator_Heap, Growth_Exponential<> > >()();
344 Functor<Storage_Reallocate<Allocator_Aligned<>,
Growth_Linear<> > >()();
347 Functor<Storage_Commit<Allocator_AddressSpace<>,
Growth_Linear<> > >()();
350 Functor<Storage_AutoCommit<> >()();
static const size_t g_PageSize
Definition: alignment.h:93
size_t Align(size_t n)
Definition: alignment.h:38
Definition: allocator_policies.h:269
Storage_AutoCommit(size_t maxCapacity_)
Definition: allocator_policies.h:272
Allocator allocator
Definition: allocator_policies.h:306
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:300
NONCOPYABLE(Storage_AutoCommit)
~Storage_AutoCommit()
Definition: allocator_policies.h:279
void * storage
Definition: allocator_policies.h:308
uintptr_t Address() const
Definition: allocator_policies.h:285
size_t Capacity() const
Definition: allocator_policies.h:290
size_t maxCapacity
Definition: allocator_policies.h:307
size_t MaxCapacity() const
Definition: allocator_policies.h:295
Definition: allocator_policies.h:210
size_t Capacity() const
Definition: allocator_policies.h:230
size_t capacity
Definition: allocator_policies.h:259
uintptr_t Address() const
Definition: allocator_policies.h:225
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:240
size_t maxCapacity
Definition: allocator_policies.h:257
~Storage_Commit()
Definition: allocator_policies.h:220
NONCOPYABLE(Storage_Commit)
size_t MaxCapacity() const
Definition: allocator_policies.h:235
void * storage
Definition: allocator_policies.h:258
Storage_Commit(size_t maxCapacity_)
Definition: allocator_policies.h:213
Allocator allocator
Definition: allocator_policies.h:256
Definition: allocator_policies.h:110
Storage_Fixed(size_t size)
Definition: allocator_policies.h:113
Allocator allocator
Definition: allocator_policies.h:145
size_t Capacity() const
Definition: allocator_policies.h:129
size_t maxCapacity
Definition: allocator_policies.h:146
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:139
NONCOPYABLE(Storage_Fixed)
size_t MaxCapacity() const
Definition: allocator_policies.h:134
uintptr_t Address() const
Definition: allocator_policies.h:124
~Storage_Fixed()
Definition: allocator_policies.h:119
void * storage
Definition: allocator_policies.h:147
Definition: allocator_policies.h:156
uintptr_t Address() const
Definition: allocator_policies.h:170
Storage_Reallocate(size_t initialCapacity)
Definition: allocator_policies.h:159
size_t capacity
Definition: allocator_policies.h:200
void * storage
Definition: allocator_policies.h:201
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:185
NONCOPYABLE(Storage_Reallocate)
Allocator allocator
Definition: allocator_policies.h:199
size_t Capacity() const
Definition: allocator_policies.h:175
size_t MaxCapacity() const
Definition: allocator_policies.h:180
~Storage_Reallocate()
Definition: allocator_policies.h:165
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning.
Definition: code_annotation.h:40
#define ASSERT(expr)
same as ENSURE in debug mode, does nothing in release mode.
Definition: debug.h:305
Definition: allocator_policies.h:36
static uintptr_t StorageAppend(Storage &storage, size_t &end, size_t size)
Definition: allocator_policies.h:320
static void ForEachStorage()
Definition: allocator_policies.h:337
void EndOnDemandCommits()
decrements the reference count begun by BeginOnDemandCommit and removes the page fault handler when i...
Definition: uvm.cpp:125
bool Commit(uintptr_t address, size_t size, PageType pageType, int prot)
map physical memory to previously reserved address space.
Definition: uvm.cpp:59
void BeginOnDemandCommits()
install a handler that attempts to commit memory whenever a read/write page fault is encountered.
Definition: uvm.cpp:120
Definition: allocator_policies.h:64
size_t operator()(size_t oldSize) const
Definition: allocator_policies.h:65
Definition: allocator_policies.h:45
size_t operator()(size_t oldSize) const
Definition: allocator_policies.h:46
Definition: allocator_policies.h:88
size_t MaxCapacity() const
uintptr_t Address() const
bool Expand(size_t requiredCapacity)