27 #ifndef ALLOCATOR_POLICIES 28 #define ALLOCATOR_POLICIES 42 template<
size_t increment = pageSize>
47 return oldSize + increment;
61 template<
size_t multiplier = 21,
size_t divisor = 16>
66 const size_t product = oldSize * multiplier;
71 ASSERT(product >= oldSize);
73 return product / divisor;
89 uintptr_t Address()
const;
92 size_t Capacity()
const;
95 size_t MaxCapacity()
const;
102 bool Expand(
size_t requiredCapacity);
107 template<
class Allocator = Allocator_Aligned<> >
114 , storage(allocator.allocate(maxCapacity))
120 allocator.deallocate(storage, maxCapacity);
125 return uintptr_t(storage);
153 template<
class Allocator = Allocator_Heap,
class GrowthPolicy = Growth_Exponential<> >
159 : capacity(initialCapacity)
160 , storage(allocator.allocate(initialCapacity))
166 allocator.deallocate(storage, capacity);
171 return uintptr_t(storage);
181 return std::numeric_limits<size_t>::max();
186 size_t newCapacity = std::max(requiredCapacity, GrowthPolicy()(capacity));
187 void* newStorage = allocator.allocate(newCapacity);
190 memcpy(newStorage, storage, capacity);
193 allocator.deallocate(newStorage, newCapacity);
207 template<
class Allocator = Allocator_AddressSpace<>,
class GrowthPolicy = Growth_Exponential<2,1> >
214 , storage(allocator.allocate(maxCapacity))
221 allocator.deallocate(storage, maxCapacity);
226 return uintptr_t(storage);
241 size_t newCapacity = std::max(requiredCapacity, GrowthPolicy()(capacity));
245 newCapacity = Align<pageSize>(newCapacity);
246 if(newCapacity > maxCapacity)
248 if(!
vm::Commit(Address()+capacity, newCapacity-capacity))
250 capacity = newCapacity;
266 template<
class Allocator = Allocator_AddressSpace<> >
273 , storage(allocator.allocate(maxCapacity))
281 allocator.deallocate(storage, maxCapacity);
286 return uintptr_t(storage);
318 template<
class Storage>
321 size_t newEnd = end + size;
324 if(!storage.
Expand(newEnd))
329 return storage.
Address() + newEnd;
335 template<
template<
class Storage>
class Functor>
338 Functor<Storage_Fixed<Allocator_Heap> >()();
339 Functor<Storage_Fixed<Allocator_Aligned<> > >()();
341 Functor<Storage_Reallocate<Allocator_Heap, Growth_Linear<> > >()();
342 Functor<Storage_Reallocate<Allocator_Heap, Growth_Exponential<> > >()();
343 Functor<Storage_Reallocate<Allocator_Aligned<>,
Growth_Linear<> > >()();
346 Functor<Storage_Commit<Allocator_AddressSpace<>, Growth_Linear<> > >()();
347 Functor<Storage_Commit<Allocator_AddressSpace<>, Growth_Exponential<> > >()();
349 Functor<Storage_AutoCommit<> >()();
354 #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:217
uintptr_t Address() const
Definition: allocator_policies.h:224
size_t operator()(size_t oldSize) const
Definition: allocator_policies.h:45
Storage_AutoCommit(size_t maxCapacity_)
Definition: allocator_policies.h:271
static const size_t pageSize
Definition: alignment.h:83
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Definition: code_annotation.h:38
size_t operator()(size_t oldSize) const
Definition: allocator_policies.h:64
void BeginOnDemandCommits()
install a handler that attempts to commit memory whenever a read/write page fault is encountered...
Definition: uvm.cpp:120
size_t Capacity() const
Definition: allocator_policies.h:174
~Storage_Fixed()
Definition: allocator_policies.h:118
size_t Align(size_t n)
Definition: alignment.h:36
Definition: allocator_policies.h:62
uintptr_t Address() const
Definition: allocator_policies.h:123
size_t MaxCapacity() const
Definition: allocator_policies.h:179
Definition: file_cache.cpp:91
uintptr_t Address() const
Definition: allocator_policies.h:284
~Storage_Reallocate()
Definition: allocator_policies.h:164
static void swap(UniqueRange &p1, UniqueRange &p2)
Definition: unique_range.h:198
size_t MaxCapacity() const
Definition: allocator_policies.h:294
#define ASSERT(expr)
same as ENSURE in debug mode, does nothing in release mode.
Definition: debug.h:315
Definition: allocator_policies.h:267
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:43
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:319
Storage_Commit(size_t maxCapacity_)
Definition: allocator_policies.h:212
~Storage_Commit()
Definition: allocator_policies.h:219
size_t Capacity() const
Definition: allocator_policies.h:289
static void ForEachStorage()
Definition: allocator_policies.h:336
Storage_Reallocate(size_t initialCapacity)
Definition: allocator_policies.h:158
size_t capacity
Definition: allocator_policies.h:258
size_t maxCapacity
Definition: allocator_policies.h:306
void EndOnDemandCommits()
decrements the reference count begun by BeginOnDemandCommit and removes the page fault handler when i...
Definition: uvm.cpp:125
Definition: allocator_policies.h:208
uintptr_t Address() const
Definition: allocator_policies.h:169
void * storage
Definition: allocator_policies.h:146
~Storage_AutoCommit()
Definition: allocator_policies.h:278
size_t Capacity() const
Definition: allocator_policies.h:229
Allocator allocator
Definition: allocator_policies.h:305
size_t MaxCapacity() const
Definition: allocator_policies.h:133
Definition: allocator_policies.h:154
Definition: allocator_policies.h:35
Allocator allocator
Definition: allocator_policies.h:144
Storage_Fixed(size_t size)
Definition: allocator_policies.h:112
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:138
size_t maxCapacity
Definition: allocator_policies.h:145
Allocator allocator
Definition: allocator_policies.h:255
size_t Capacity() const
Definition: allocator_policies.h:128
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:299
void * storage
Definition: allocator_policies.h:307
void * storage
Definition: allocator_policies.h:200
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:239
Definition: allocator_policies.h:86
Allocator allocator
Definition: allocator_policies.h:198
bool Expand(size_t requiredCapacity)
Definition: allocator_policies.h:184
size_t MaxCapacity() const
Definition: allocator_policies.h:234
uintptr_t Address() const
size_t maxCapacity
Definition: allocator_policies.h:256
void * storage
Definition: allocator_policies.h:257
size_t capacity
Definition: allocator_policies.h:199
Definition: allocator_policies.h:108