27 #ifndef ALLOCATOR_POLICIES
28 #define ALLOCATOR_POLICIES
35 namespace Allocators {
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;
102 bool Expand(
size_t requiredCapacity);
107 template<
class Allocator = Allocator_Aligned<> >
153 template<
class Allocator = Allocator_Heap,
class GrowthPolicy = Growth_Exponential<> >
181 return std::numeric_limits<size_t>::max();
186 size_t newCapacity = std::max(requiredCapacity, GrowthPolicy()(
capacity));
187 void* newStorage =
allocator.allocate(newCapacity);
193 allocator.deallocate(newStorage, newCapacity);
207 template<
class Allocator = Allocator_AddressSpace<>,
class GrowthPolicy = Growth_Exponential<2,1> >
241 size_t newCapacity = std::max(requiredCapacity, GrowthPolicy()(
capacity));
245 newCapacity = Align<pageSize>(newCapacity);
266 template<
class Allocator = Allocator_AddressSpace<> >
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
uintptr_t Address() const
size_t operator()(size_t oldSize) const
Storage_AutoCommit(size_t maxCapacity_)
static const size_t pageSize
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
size_t operator()(size_t oldSize) const
void BeginOnDemandCommits()
install a handler that attempts to commit memory whenever a read/write page fault is encountered...
uintptr_t Address() const
size_t MaxCapacity() const
size_t MaxCapacity() const
uintptr_t Address() const
static void swap(UniqueRange &p1, UniqueRange &p2)
size_t MaxCapacity() const
#define ASSERT(expr)
same as ENSURE in debug mode, does nothing in release mode.
bool Expand(size_t requiredCapacity)
bool Commit(uintptr_t address, size_t size, PageType pageType, int prot)
map physical memory to previously reserved address space.
static uintptr_t StorageAppend(Storage &storage, size_t &end, size_t size)
Storage_Commit(size_t maxCapacity_)
NONCOPYABLE(Storage_Reallocate)
NONCOPYABLE(Storage_Fixed)
static void ForEachStorage()
Storage_Reallocate(size_t initialCapacity)
void EndOnDemandCommits()
decrements the reference count begun by BeginOnDemandCommit and removes the page fault handler when i...
uintptr_t Address() const
size_t MaxCapacity() const
Storage_Fixed(size_t size)
bool Expand(size_t requiredCapacity)
bool Expand(size_t requiredCapacity)
NONCOPYABLE(Storage_AutoCommit)
bool Expand(size_t requiredCapacity)
bool Expand(size_t requiredCapacity)
size_t MaxCapacity() const
uintptr_t Address() const
NONCOPYABLE(Storage_Commit)