28 #include <unordered_map>
38 #define CHAR_PTR(c) ((char*)c)
138 #ifdef DEBUG_OBJECT_MODEL
139 inline void freeRAM(
bool isContained,
141 std::vector<InactiveAllocationBlock>& allInactives,
147 std::vector<InactiveAllocationBlock>& allInactives,
151 std::cout <<
"Default policy!!\n";
156 #ifdef DEBUG_OBJECT_MODEL
179 #ifdef DEBUG_OBJECT_MODEL
180 inline void freeRAM(
bool isContained,
182 std::vector<InactiveAllocationBlock>& allInactives,
186 inline void freeRAM(
bool isContained,
188 std::vector<InactiveAllocationBlock>& allInactives,
194 #ifdef DEBUG_OBJECT_MODEL
212 #ifdef DEBUG_OBJECT_MODEL
213 inline void freeRAM(
bool isContained,
215 std::vector<InactiveAllocationBlock>& allInactives,
219 inline void freeRAM(
bool isContained,
221 std::vector<InactiveAllocationBlock>& allInactives,
228 #ifdef DEBUG_OBJECT_MODEL
246 #ifdef DEBUG_OBJECT_MODEL
247 inline void freeRAM(
bool isContained,
249 std::vector<InactiveAllocationBlock>& allInactives,
253 inline void freeRAM(
bool isContained,
255 std::vector<InactiveAllocationBlock>& allInactives,
261 #ifdef DEBUG_OBJECT_MODEL
276 template <
typename FirstPolicy,
typename... OtherPolicies>
283 template <
typename... OtherPolicies>
290 template <
typename... OtherPolicies>
292 typename std::enable_if<
sizeof...(OtherPolicies) == 0,
DummyPolicy>::type
first();
297 template <
typename FirstPolicy,
typename... OtherPolicies>
304 decltype(first<OtherPolicies...>()) theRest;
311 if (firstPolicy.getPolicyName() == toMe) {
315 theRest.unsetPolicy();
321 theRest.setPolicy(toMe);
328 theRest.unsetPolicy();
332 #ifdef DEBUG_OBJECT_MODEL
333 inline void freeRAM(
bool isContained,
335 std::vector<InactiveAllocationBlock>& allInactives,
341 std::vector<InactiveAllocationBlock>& allInactives,
346 #ifdef DEBUG_OBJECT_MODEL
348 firstPolicy.freeRAM(isContained, here, allInactives, myState, typeId);
350 firstPolicy.freeRAM(isContained, here, allInactives, myState);
353 #ifdef DEBUG_OBJECT_MODEL
355 theRest.freeRAM(isContained, here, allInactives, myState, typeId);
357 theRest.freeRAM(isContained, here, allInactives, myState);
362 #ifdef DEBUG_OBJECT_MODEL
369 #ifdef DEBUG_OBJECT_MODEL
371 return firstPolicy.getRAM(howMuch, myState, typeId);
373 return firstPolicy.getRAM(howMuch, myState);
376 #ifdef DEBUG_OBJECT_MODEL
378 return theRest.getRAM(howMuch, myState, typeId);
380 return theRest.getRAM(howMuch, myState);
390 virtual const char*
what()
const throw() {
391 return "Not enough free memory in current allocation block.\n";
398 template <
class ObjType>
406 template <
typename FirstPolicy,
typename... OtherPolicies>
440 inline void emptyOutBlock(
void* here);
443 template <
class ObjType>
456 inline bool contains(
void* whereIn);
461 inline bool isManaged(
void* here);
467 #ifdef DEBUG_OBJECT_MODEL
468 inline void*
getRAM(
size_t howMuch, int16_t typeId);
470 inline void*
getRAM(
size_t howMuch);
474 #ifdef DEBUG_OBJECT_MODEL
475 inline void freeRAM(
void* here, int16_t typeId);
477 inline void freeRAM(
void* here);
481 inline void setupBlock(
void* where,
size_t numBytesIn,
bool throwExceptionOnFail);
484 inline void setupUserSuppliedBlock(
void* where,
size_t numBytesIn,
bool throwExceptionOnFail);
497 template <
class ObjType>
502 AllocatorState temporarilyUseBlockForAllocations(
void* putMeHere,
size_t numBytesAvailable);
503 AllocatorState temporarilyUseBlockForAllocations(
size_t numBytesAvailable);
510 inline std::string printCurrentBlock();
511 inline std::string printInactiveBlocks();
514 inline void cleanInactiveBlocks();
516 inline void cleanInactiveBlocks(
size_t size);
bool curBlockUserSupplied
size_t getBytesAvailableInCurrentAllocatorBlock()
MultiPolicyAllocator< DefaultPolicy, NoReusePolicy, NoReferenceCountPolicy > Allocator
friend bool operator>(const InactiveAllocationBlock &in, const void *compToMe)
InactiveAllocationBlock()
void * getRAM(size_t howMuch, AllocatorState &myState)
Allocator & getAllocator()
void * getRAM(size_t howMuch, AllocatorState &myState)
NotEnoughSpace myException
std::vector< InactiveAllocationBlock > allInactives
unsigned getReferenceCount()
friend bool operator==(const InactiveAllocationBlock &in, const void *compToMe)
std::vector< std::vector< void * > > chunks
void freeRAM(bool isContained, void *here, std::vector< InactiveAllocationBlock > &allInactives, AllocatorState &myState)
PolicyList< OtherPolicies...>::type first()
unsigned getNumObjectsInHomeAllocatorBlock(Handle< ObjType > &forMe)
void freeRAM(bool isContained, void *here, std::vector< InactiveAllocationBlock > &allInactives, AllocatorState &myState)
friend bool operator<(const InactiveAllocationBlock &in, const void *compToMe)
void setPolicy(AllocatorPolicy toMe)
unsigned getNumObjectsInAllocatorBlock(void *forMe)
PolicyList< FirstPolicy, OtherPolicies...> myPolicies
virtual const char * what() const
unsigned getNumObjectsInCurrentAllocatorBlock()
AllocatorPolicy getPolicyName()
void makeObjectAllocatorBlock(size_t numBytesIn, bool throwExceptionOnFail)
AllocatorPolicy getPolicyName()
AllocatorPolicy getPolicyName()