55// //////////////////////////////////////////////////////////////////////////
66#pragma once
77
8+ #include " xrCore/Memory/memory_allocator_options.h"
9+
810class XRCORE_API doug_lea_allocator
911{
1012public:
@@ -31,3 +33,90 @@ class XRCORE_API doug_lea_allocator
3133 pcstr m_arena_id;
3234 void * m_dl_arena;
3335};
36+
37+ extern doug_lea_allocator common;
38+
39+ template <class T , doug_lea_allocator& _impl = common>
40+ class doug_lea_alloc
41+ {
42+ constexpr static doug_lea_allocator& impl = _impl;
43+
44+ public:
45+ using size_type = size_t ;
46+ using difference_type = ptrdiff_t ;
47+ using pointer = T * ;
48+ using const_pointer = const T*;
49+ using reference = T & ;
50+ using const_reference = const T&;
51+ using value_type = T;
52+
53+ template <class _Other >
54+ struct rebind
55+ {
56+ using other = doug_lea_alloc<_Other>;
57+ };
58+
59+ doug_lea_alloc () {}
60+ doug_lea_alloc (const doug_lea_alloc<T>&) {}
61+
62+ template <class _Other >
63+ doug_lea_alloc (const doug_lea_alloc<_Other>&) {}
64+
65+ template <class _Other >
66+ doug_lea_alloc<T>& operator =(const doug_lea_alloc<_Other>&)
67+ {
68+ return *this ;
69+ }
70+
71+ pointer address (reference _Val) const { return (&_Val); }
72+ const_pointer address (const_reference _Val) const { return (&_Val); }
73+
74+ pointer allocate (size_type n, const void * /* p*/ = nullptr ) const
75+ {
76+ return static_cast <T*>(impl.malloc_impl (sizeof (T) * (u32 )n));
77+ }
78+
79+ void deallocate (pointer p, size_type) const { impl.free_impl ((void *&)p); }
80+ void deallocate (void * p, size_type n) const { impl.free_impl (p); }
81+ char * __charalloc (size_type n) { return (char *)allocate (n); }
82+ void construct (pointer p, const T& _Val) { new (p) T (_Val); }
83+ void destroy (pointer p) { p->~T (); }
84+
85+ size_type max_size () const
86+ {
87+ constexpr size_type _Count = static_cast <size_type>(-1 ) / sizeof (T);
88+ return 0 < _Count ? _Count : 1 ;
89+ }
90+ };
91+
92+ template <class _Ty , class _Other >
93+ bool operator ==(const doug_lea_alloc<_Ty>&, const doug_lea_alloc<_Other>&)
94+ {
95+ return (true );
96+ }
97+
98+ template <class _Ty , class _Other >
99+ bool operator !=(const doug_lea_alloc<_Ty>&, const doug_lea_alloc<_Other>&)
100+ {
101+ return (false );
102+ }
103+
104+ template <doug_lea_allocator& _impl = common>
105+ struct doug_lea_allocator_wrapper
106+ {
107+ constexpr static doug_lea_allocator& impl = _impl;
108+
109+ template <typename T>
110+ struct helper
111+ {
112+ using result = doug_lea_alloc<T, _impl>;
113+ };
114+
115+ static void * alloc (const u32 & n) { return impl.malloc_impl ((u32 )n); }
116+
117+ template <typename T>
118+ static void dealloc (T*& p)
119+ {
120+ impl.free_impl ((void *&)p);
121+ }
122+ };
0 commit comments