25#include <kiwano/macros.h>
39 virtual void*
Alloc(
size_t size) = 0;
43 virtual void Free(
void* ptr) = 0;
56inline void* Alloc(
size_t size)
58 return memory::GetAllocator()->Alloc(size);
63inline void Free(
void* ptr)
65 memory::GetAllocator()->Free(ptr);
72template <
typename _Ty>
76 typedef _Ty value_type;
78 typedef const _Ty* const_pointer;
79 typedef _Ty& reference;
80 typedef const _Ty& const_reference;
82 using size_type = size_t;
83 using difference_type = ptrdiff_t;
85 template <
class _Other>
95 template <
class _Other>
100 inline _Ty* allocate(
size_t count)
104 return static_cast<_Ty*
>(memory::Alloc(
sizeof(_Ty) * count));
109 inline void* allocate(
size_t count,
const void*)
111 return allocate(count);
114 inline void deallocate(
void* ptr,
size_t count)
119 template <
typename _UTy,
typename... _Args>
120 inline void construct(_UTy*
const ptr, _Args&&... args)
122 ::new (
const_cast<void*
>(
static_cast<const volatile void*
>(ptr))) _Ty(std::forward<_Args>(args)...);
125 template <
typename _UTy>
126 inline void destroy(_UTy* ptr)
131 size_t max_size() const noexcept
133 return std::numeric_limits<size_t>::max() /
sizeof(_Ty);
136 _Ty* address(_Ty& val)
const noexcept
138 return std::addressof(val);
141 const _Ty* address(
const _Ty& val)
const noexcept
143 return std::addressof(val);
152 using value_type = void;
153 typedef void* pointer;
154 typedef const void* const_pointer;
156 using size_type = size_t;
157 using difference_type = ptrdiff_t;
159 template <
class _Other>
166template <
class _Ty,
class _Other>
172template <
class _Ty,
class _Other>
173bool operator!=(
const Allocator<_Ty>&,
const Allocator<_Other>&)
noexcept
分配器
Definition: Allocator.h:74
内存分配器
Definition: Allocator.h:35
virtual void Free(void *ptr)=0
释放内存
virtual void * Alloc(size_t size)=0
申请内存
Definition: Allocator.h:87