Skip to content

Commit e86e49e

Browse files
committed
Refactor allocators
New XRay::xray_allocator and XRay::xray_allocator_wrapper aliases Not deleted Doug Lea allocator but disabled it since it's unused Remove throw() specifiers from new/delete operators
1 parent c22cf4c commit e86e49e

16 files changed

+62
-60
lines changed

src/xrCommon/xr_deque.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#pragma once
22
#include <deque>
3-
#include "xrCore/Memory/xalloc.h"
4-
#include "xrCore/xrDebug_macros.h"
3+
#include "xrCore/Memory/XRayAllocator.hpp"
54

6-
template <typename T, typename allocator = xalloc<T>>
5+
template <typename T, typename allocator = XRay::xray_allocator<T>>
76
class xr_deque : public std::deque<T, allocator>
87
{
98
public:

src/xrCommon/xr_list.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#pragma once
22
#include <list>
3-
#include "xrCore/Memory/xalloc.h"
4-
#include "xrCore/xrDebug_macros.h"
3+
#include "xrCore/Memory/XRayAllocator.hpp"
54

6-
template <typename T, typename allocator = xalloc<T>>
5+
template <typename T, typename allocator = XRay::xray_allocator<T>>
76
class xr_list : public std::list<T, allocator>
87
{
98
public:

src/xrCommon/xr_map.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#pragma once
22
#include <map>
3-
#include "xrCore/Memory/xalloc.h"
4-
#include "xrCore/xrDebug_macros.h"
3+
#include "xrCore/Memory/XRayAllocator.hpp"
54

6-
template <typename K, class V, class P = std::less<K>, typename allocator = xalloc<std::pair<K, V>>>
5+
template <typename K, class V, class P = std::less<K>, typename allocator = XRay::xray_allocator<std::pair<K, V>>>
76
class xr_map : public std::map<K, V, P, allocator>
87
{
98
public:
109
u32 size() const { return (u32)std::map<K, V, P, allocator>::size(); }
1110
};
1211

13-
template <typename K, class V, class P = std::less<K>, typename allocator = xalloc<std::pair<K, V>>>
12+
template <typename K, class V, class P = std::less<K>, typename allocator = XRay::xray_allocator<std::pair<K, V>>>
1413
class xr_multimap : public std::multimap<K, V, P, allocator>
1514
{
1615
public:

src/xrCommon/xr_set.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#pragma once
22
#include <set>
3-
#include "xrCore/Memory/xalloc.h"
4-
#include "xrCore/xrDebug_macros.h"
3+
#include "xrCore/Memory/XRayAllocator.hpp"
54

6-
template <typename K, class P = std::less<K>, typename allocator = xalloc<K>>
5+
template <typename K, class P = std::less<K>, typename allocator = XRay::xray_allocator<K>>
76
class xr_set : public std::set<K, P, allocator>
87
{
98
public:
109
u32 size() const { return (u32)std::set<K, P, allocator>::size(); }
1110
};
1211

13-
template <typename K, class P = std::less<K>, typename allocator = xalloc<K>>
12+
template <typename K, class P = std::less<K>, typename allocator = XRay::xray_allocator<K>>
1413
class xr_multiset : public std::multiset<K, P, allocator>
1514
{
1615
public:

src/xrCommon/xr_string.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#pragma once
22
#include <string>
3-
#include "xrCore/Memory/xalloc.h"
3+
#include "xrCore/Memory/XRayAllocator.hpp"
44

55
// string(char)
6-
typedef std::basic_string<char, std::char_traits<char>, xalloc<char>> xr_string;
6+
using xr_string = std::basic_string<char, std::char_traits<char>, XRay::xray_allocator<char>>;
77

88
inline void xr_strlwr(xr_string& src)
99
{
10-
for (xr_string::iterator it = src.begin(); it!=src.end(); it++)
11-
*it = xr_string::value_type(tolower(*it));
10+
for (auto& it : src)
11+
it = xr_string::value_type(tolower(it));
1212
}

src/xrCommon/xr_vector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
#include <vector>
3-
#include "xrCore/Memory/xalloc.h"
3+
#include "xrCore/Memory/XRayAllocator.hpp"
44

55
#define DEF_VECTOR(N, T)\
66
typedef xr_vector<T> N;\
@@ -10,5 +10,5 @@
1010
typedef xr_vector<T> N;\
1111
typedef N::iterator I;
1212

13-
template <typename T, typename allocator = xalloc<T>>
13+
template <typename T, typename allocator = XRay::xray_allocator<T>>
1414
using xr_vector = class std::vector<T, allocator>;

src/xrCore/FixedMap.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#ifndef _FIXEDMAP_H
2-
#define _FIXEDMAP_H
31
#pragma once
42

5-
template <class K, class T, class allocator = xr_allocator>
3+
template <class K, class T, class allocator = XRay::xray_allocator_wrapper>
64
class FixedMAP
75
{
86
enum
@@ -301,4 +299,3 @@ class FixedMAP
301299
CB(nodes + i);
302300
}
303301
};
304-
#endif

src/xrCore/Memory/XRayAllocator.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
#include "memory_allocator_options.h"
3+
#include "xalloc.h"
4+
#ifdef USE_DOUG_LEA_ALLOCATOR
5+
#include "doug_lea_allocator.h"
6+
#endif
7+
8+
namespace XRay
9+
{
10+
template<typename T>
11+
using xray_allocator = xalloc<T>;
12+
using xray_allocator_wrapper = xr_allocator;
13+
} // namespace XRay

src/xrCore/Memory/doug_lea_allocator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
#include "stdafx.h"
88
#include "doug_lea_allocator.h"
99

10+
#ifdef USE_DOUG_LEA_ALLOCATOR
1011
#define USE_DL_PREFIX
1112
#define MSPACES 1
1213
#define USE_OUT_OF_MEMORY_HANDLER
1314
#define USE_LOCKS 0
14-
#include "Memory/dlmalloc.h"
15+
#include "dlmalloc.h"
1516

1617
static void __stdcall out_of_memory(mspace const space, void const* const parameter, int const first_time)
1718
{
@@ -51,3 +52,4 @@ void doug_lea_allocator::free_impl(void*& pointer)
5152
}
5253

5354
u32 doug_lea_allocator::get_allocated_size() const { return (u32)mspace_mallinfo(m_dl_arena).uordblks; }
55+
#endif // USE_DOUG_LEA_ALLOCATOR

src/xrCore/Memory/doug_lea_allocator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
////////////////////////////////////////////////////////////////////////////
66
#pragma once
77

8-
#include "xrCore/Memory/memory_allocator_options.h"
9-
8+
#ifdef USE_DOUG_LEA_ALLOCATOR
109
class XRCORE_API doug_lea_allocator
1110
{
1211
public:
@@ -120,3 +119,4 @@ struct doug_lea_allocator_wrapper
120119
impl.free_impl((void*&)p);
121120
}
122121
};
122+
#endif // USE_DOUG_LEA_ALLOCATOR

0 commit comments

Comments
 (0)