123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #ifndef CC_ALLOCATOR_BASE_H
- #define CC_ALLOCATOR_BASE_H
- #include <string>
- #include "platform/CCPlatformMacros.h"
- #include "base/allocator/CCAllocatorMacros.h"
- NS_CC_BEGIN
- NS_CC_ALLOCATOR_BEGIN
- class AllocatorBase
- {
- public:
-
- typedef void* pointer;
-
- enum { kDefaultAlignment = 16 };
-
-
-
- static_assert(sizeof(uintptr_t) <= kDefaultAlignment, "pointer size must be smaller than default alignment");
-
- #if CC_ENABLE_ALLOCATOR_DIAGNOSTICS
- AllocatorBase()
- : _next_allocator(nullptr)
- {}
- #endif
-
- virtual ~AllocatorBase()
- {}
-
-
-
-
- CC_ALLOCATOR_INLINE pointer aligned(const pointer address, const size_t alignment = kDefaultAlignment) const
- {
- return (pointer) (((intptr_t)address + (alignment - 1)) & ~(alignment - 1));
- }
-
-
-
-
-
- CC_ALLOCATOR_INLINE size_t nextPow2BlockSize(size_t size) const
- {
- --size;
- size |= size >> 1;
- size |= size >> 2;
- size |= size >> 4;
- size |= size >> 8;
- size |= size >> 16;
- return ++size;
- }
-
- #if CC_ENABLE_ALLOCATOR_DIAGNOSTICS
- void setTag(const char* tag)
- {
- strncpy(_tag, tag, sizeof(_tag)-1);
- }
-
- const char* tag() const
- {
- return _tag;
- }
-
-
-
- char _tag[1000];
-
-
- virtual std::string diagnostics() const
- {
- return "";
- }
- AllocatorBase* _next_allocator;
- #endif
- };
- NS_CC_ALLOCATOR_END
- NS_CC_END
- #endif
|