99class XRCORE_API doug_lea_allocator
1010{
1111public:
12- doug_lea_allocator (void * arena, u32 arena_size, pcstr arena_id);
12+ doug_lea_allocator (void * arena, size_t arena_size, pcstr arena_id);
1313 ~doug_lea_allocator ();
14- void * malloc_impl (u32 size);
15- void * realloc_impl (void * pointer, u32 new_size);
16- void free_impl (void *& pointer);
17- u32 get_allocated_size () const ;
14+ void * malloc_impl (size_t size);
15+ void * realloc_impl (void * pointer, size_t new_size);
16+ void free_impl (void * pointer);
17+ size_t get_allocated_size () const ;
1818 pcstr get_arena_id () const { return m_arena_id; }
1919 template <typename T>
2020 void free_impl (T*& pointer)
@@ -23,7 +23,7 @@ class XRCORE_API doug_lea_allocator
2323 }
2424
2525 template <typename T>
26- T* alloc_impl (u32 const count)
26+ T* alloc_impl (const size_t count)
2727 {
2828 return (T*)malloc_impl (count * sizeof (T));
2929 }
@@ -33,74 +33,73 @@ class XRCORE_API doug_lea_allocator
3333 void * m_dl_arena;
3434};
3535
36- extern doug_lea_allocator g_common_allocator ;
36+ extern doug_lea_allocator g_common_doug_lea_allocator ;
3737
38- template <class T , doug_lea_allocator& _impl = common >
38+ template <class T , doug_lea_allocator& _impl = g_common_doug_lea_allocator >
3939class doug_lea_alloc
4040{
4141 constexpr static doug_lea_allocator& impl = _impl;
4242
4343public:
4444 using size_type = size_t ;
4545 using difference_type = ptrdiff_t ;
46- using pointer = T * ;
46+ using pointer = T* ;
4747 using const_pointer = const T*;
48- using reference = T & ;
48+ using reference = T& ;
4949 using const_reference = const T&;
5050 using value_type = T;
5151
52- template <class _Other >
52+ template <class Other >
5353 struct rebind
5454 {
55- using other = doug_lea_alloc<_Other >;
55+ using other = doug_lea_alloc<Other >;
5656 };
5757
58- doug_lea_alloc () {}
59- doug_lea_alloc (const doug_lea_alloc<T>&) {}
58+ doug_lea_alloc () = default;
59+ doug_lea_alloc (const doug_lea_alloc<T, _impl >&) = default;
6060
61- template <class _Other >
62- doug_lea_alloc (const doug_lea_alloc<_Other >&) {}
61+ template <class Other >
62+ doug_lea_alloc (const doug_lea_alloc<Other >&) {}
6363
64- template <class _Other >
65- doug_lea_alloc<T>& operator =(const doug_lea_alloc<_Other >&)
64+ template <class Other >
65+ doug_lea_alloc<T>& operator =(const doug_lea_alloc<Other >&)
6666 {
6767 return *this ;
6868 }
6969
70- pointer address (reference _Val ) const { return (&_Val) ; }
71- const_pointer address (const_reference _Val ) const { return (&_Val) ; }
70+ pointer address (reference ref ) const { return &ref ; }
71+ const_pointer address (const_reference ref ) const { return &ref ; }
7272
7373 pointer allocate (size_type n, const void * /* p*/ = nullptr ) const
7474 {
75- return static_cast <T* >(impl.malloc_impl (sizeof (T) * ( u32 ) n));
75+ return static_cast <pointer >(impl.malloc_impl (sizeof (T) * n));
7676 }
7777
78- void deallocate (pointer p, size_type) const { impl.free_impl ((void *&)p); }
79- void deallocate (void * p, size_type n) const { impl.free_impl (p); }
80- char * __charalloc (size_type n) { return (char *)allocate (n); }
81- void construct (pointer p, const T& _Val) { new (p) T (_Val); }
78+ void deallocate (pointer p, size_type /* n*/ ) const { impl.free_impl ((void *&)p); }
79+ void deallocate (void * p, size_type /* n*/ ) const { impl.free_impl (p); }
80+ void construct (pointer p, const T& ref) { new (p) T (ref); }
8281 void destroy (pointer p) { p->~T (); }
8382
8483 size_type max_size () const
8584 {
86- constexpr size_type _Count = static_cast <size_type>(- 1 ) / sizeof (T);
87- return 0 < _Count ? _Count : 1 ;
85+ constexpr auto count = std::numeric_limits <size_type>:: max ( ) / sizeof (T);
86+ return 0 < count ? count : 1 ;
8887 }
8988};
9089
91- template <class _Ty , class _Other >
92- bool operator ==(const doug_lea_alloc<_Ty >&, const doug_lea_alloc<_Other >&)
90+ template <class T , class Other >
91+ bool operator ==(const doug_lea_alloc<T >&, const doug_lea_alloc<Other >&)
9392{
94- return ( true ) ;
93+ return true ;
9594}
9695
97- template <class _Ty , class _Other >
98- bool operator !=(const doug_lea_alloc<_Ty >&, const doug_lea_alloc<_Other >&)
96+ template <class T , class Other >
97+ bool operator !=(const doug_lea_alloc<T >&, const doug_lea_alloc<Other >&)
9998{
100- return ( false ) ;
99+ return false ;
101100}
102101
103- template <doug_lea_allocator& _impl = common >
102+ template <doug_lea_allocator& _impl = g_common_doug_lea_allocator >
104103struct doug_lea_allocator_wrapper
105104{
106105 constexpr static doug_lea_allocator& impl = _impl;
@@ -111,7 +110,7 @@ struct doug_lea_allocator_wrapper
111110 using result = doug_lea_alloc<T, _impl>;
112111 };
113112
114- static void * alloc (const u32 & n) { return impl.malloc_impl (( u32 ) n); }
113+ static void * alloc (const size_t & n) { return impl.malloc_impl (n); }
115114
116115 template <typename T>
117116 static void dealloc (T*& p)
0 commit comments