27 #ifndef ALLOCATOR_POLICIES 28 #define ALLOCATOR_POLICIES 43 template<
size_t increment = g_PageSize>
48 return oldSize + increment;
62 template<
size_t multiplier = 21,
size_t divisor = 16>
67 const size_t product = oldSize * multiplier;
72 ASSERT(product >= oldSize);
74 return product / divisor;
90 uintptr_t Address()
const;
93 size_t Capacity()
const;
96 size_t MaxCapacity()
const;
103 bool Expand(
size_t requiredCapacity);
108 template<
class Allocator = Allocator_Aligned<> >
115 , storage(allocator.allocate(maxCapacity))
121 allocator.deallocate(storage, maxCapacity);
126 return uintptr_t(storage);
154 template<
class Allocator = Allocator_Heap,
class GrowthPolicy = Growth_Exponential<> >
160 : capacity(initialCapacity)
161 , storage(allocator.allocate(initialCapacity))
167 allocator.deallocate(storage, capacity);
172 return uintptr_t(storage);
182 return std::numeric_limits<size_t>::max();
187 size_t newCapacity = std::max(requiredCapacity, GrowthPolicy()(capacity));
188 void* newStorage = allocator.allocate(newCapacity);
191 memcpy(newStorage, storage, capacity);
194 allocator.deallocate(newStorage, newCapacity);
208 template<
class Allocator = Allocator_AddressSpace<>,
class GrowthPolicy = Growth_Exponential<2,1> >
215 , storage(allocator.allocate(maxCapacity))
222 allocator.deallocate(storage, maxCapacity);
227 return uintptr_t(storage);
242 size_t newCapacity = std::max(requiredCapacity, GrowthPolicy()(capacity));
246 newCapacity = Align<g_PageSize>(newCapacity);
247 if(newCapacity > maxCapacity)
249 if(!
vm::Commit(Address()+capacity, newCapacity-capacity))
251 capacity = newCapacity;
267 template<
class Allocator = Allocator_AddressSpace<> >
274 , storage(allocator.allocate(maxCapacity))
282 allocator.deallocate(storage, maxCapacity);
287 return uintptr_t(storage);
319 template<
class Storage>
322 size_t newEnd = end + size;
325 if(!storage.
Expand(newEnd))
330 return storage.
Address() + newEnd;
336 template<
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<> > >()();
348 Functor<Storage_Commit<Allocator_AddressSpace<>, Growth_Exponential<> > >()();
350 Functor<Storage_AutoCommit<> >()();
355 #endif // #ifndef ALLOCATOR_POLICIES #define NONCOPYABLE(className)
Indicates that a class is noncopyable (usually due to const or reference members, or because the clas...
Definition: code_annotation.h:227
void EndOnDemandCommits()
decrements the reference count begun by BeginOnDemandCommit and removes the page fault handler when i...
Definition: uvm.cpp:125
size_t operator()(size_t oldSize) const
Definition: allocator_policies.h:46
size_t Capacity() const
Definition: allocator_policies.h:290
Storage_AutoCommit(size_t maxCapacity_)
Definition: allocator_policies.h:272
uintptr_t Address() const
Definition: allocator_policies.h:285
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Definition: code_annotation.h:38
size_t MaxCapacity() const
Definition: allocator_policies.h:180
~Storage_Fixed()
Definition: allocator_policies.h:119
size_t Align(size_t n)
Definition: alignment.h:36
Definition: allocator_policies.h:63
size_t Capacity() const
Definition: allocator_policies.h:230
~Storage_Reallocate()
Definition: allocator_policies.h:165
static const size_t g_PageSize
Definition: alignment.h:91
#define ASSERT(expr)
same as ENSURE in debug mode, does nothing in release mode.
Definition: debug.h:318
Definition: allocator_policies.h:268
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:44
bool Commit(uintptr_t address, size_t size, PageType pageType, int prot)
map physical memory to previously reserved address space.
Definition: uvm.cpp:59
static uintptr_t StorageAppend(Storage &storage, size_t &end, size_t size)
Definition: allocator_policies.h:320
size_t MaxCapacity() const
Definition: allocator_policies.h:235
uintptr_t Address() const
Definition: allocator_policies.h:124
Storage_Commit(size_t maxCapacity_)
Definition: allocator_policies.h:213
~Storage_Commit()
Definition: allocator_policies.h:220
static void ForEachStorage()
Definition: allocator_policies.h:337
Storage_Reallocate(size_t initialCapacity)
Definition: allocator_policies.h:159
size_t capacity
Definition: allocator_policies.h:259
uintptr_t Address() const
Definition: allocator_policies.h:170
size_t maxCapacity
Definition: allocator_policies.h:307
Definition: allocator_policies.h:209
uintptr_t Address() const
void * storage
Definition: allocator_policies.h:147
~Storage_AutoCommit()
Definition: allocator_policies.h:279
size_t Capacity() const
Definition: allocator_policies.h:129
uintptr_t Address() const
Definition: allocator_policies.h:225
size_t MaxCapacity() const
Definition: allocator_policies.h:134
size_t MaxCapacity() const
Definition: allocator_policies.h:295
void BeginOnDemandCommits()
install a handler that attempts to commit memory whenever a read/write page fault is encountered...
Definition: uvm.cpp:120
Allocator allocator
Definition: allocator_policies.h:306
Definition: allocator_policies.h:155
Definition: allocator_policies.h:36
Allocator allocator
Definition: allocator_policies.h:145
Storage_Fixed(size_t size)
Definition: allocator_policies.h:113
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:139
size_t maxCapacity
Definition: allocator_policies.h:146
Allocator allocator
Definition: allocator_policies.h:256
size_t operator()(size_t oldSize) const
Definition: allocator_policies.h:65
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:300
void * storage
Definition: allocator_policies.h:308
void * storage
Definition: allocator_policies.h:201
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:240
Definition: allocator_policies.h:87
Allocator allocator
Definition: allocator_policies.h:199
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:185
size_t maxCapacity
Definition: allocator_policies.h:257
void * storage
Definition: allocator_policies.h:258
size_t capacity
Definition: allocator_policies.h:200
Definition: allocator_policies.h:109
size_t Capacity() const
Definition: allocator_policies.h:175