Skip to content

Commit a9eb04f

Browse files
intorrXottab-DUTY
authored andcommitted
Part 1 of the experiment to remove doug_lea_allocator.
1 parent 2ba0a72 commit a9eb04f

22 files changed

+49
-247
lines changed

Externals/OPCODE/OPC_AABBTree.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ AABBTree::AABBTree() : mIndices(nullptr), mTotalNbNodes(0) {}
347347
* Destructor.
348348
*/
349349
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
350-
AABBTree::~AABBTree() { CFREE(mIndices); }
350+
AABBTree::~AABBTree() { xr_free(mIndices); }
351351
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
352352
/**
353353
* Builds a generic AABB tree from a tree builder.
@@ -366,8 +366,8 @@ bool AABBTree::Build(AABBTreeBuilder* builder)
366366
builder->SetNbInvalidSplits(0);
367367

368368
// Initialize indices. This list will be modified during build.
369-
CFREE(mIndices);
370-
mIndices = CALLOC(udword, builder->mNbPrimitives);
369+
xr_free(mIndices);
370+
mIndices = xr_alloc<udword>(builder->mNbPrimitives);
371371
CHECKALLOC(mIndices);
372372
for (udword i = 0; i < builder->mNbPrimitives; i++)
373373
mIndices[i] = i;

Externals/OPCODE/OPC_Container.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ bool Container::Resize(udword needed)
9494
mMaxNbEntries = mCurNbEntries + needed;
9595

9696
// Get some bytes for _new_ entries
97-
udword* NewEntries = CALLOC(udword, mMaxNbEntries);
97+
udword* NewEntries = xr_alloc<udword>(mMaxNbEntries);
9898
CHECKALLOC(NewEntries);
9999

100100
#ifdef CONTAINER_STATS
@@ -107,7 +107,7 @@ bool Container::Resize(udword needed)
107107
CopyMemory(NewEntries, mEntries, mCurNbEntries * sizeof(udword));
108108

109109
// Delete old data
110-
CFREE(mEntries);
110+
xr_free(mEntries);
111111

112112
// Assign _new_ pointer
113113
mEntries = NewEntries;
@@ -135,7 +135,7 @@ bool Container::SetSize(udword nb)
135135
mMaxNbEntries = nb;
136136

137137
// Get some bytes for _new_ entries
138-
mEntries = CALLOC(udword, mMaxNbEntries);
138+
mEntries = xr_alloc<udword>(mMaxNbEntries);
139139
CHECKALLOC(mEntries);
140140

141141
#ifdef CONTAINER_STATS
@@ -164,7 +164,7 @@ bool Container::Refit()
164164
return false;
165165

166166
// Get just enough bytes
167-
udword* NewEntries = CALLOC(udword, mMaxNbEntries);
167+
udword* NewEntries = xr_alloc<udword>(mMaxNbEntries);
168168
CHECKALLOC(NewEntries);
169169

170170
#ifdef CONTAINER_STATS
@@ -176,7 +176,7 @@ bool Container::Refit()
176176
CopyMemory(NewEntries, mEntries, mCurNbEntries * sizeof(udword));
177177

178178
// Delete old data
179-
CFREE(mEntries);
179+
xr_free(mEntries);
180180

181181
// Assign _new_ pointer
182182
mEntries = NewEntries;

Externals/OPCODE/OPC_Container.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class ICECORE_API Container
116116
#ifdef CONTAINER_STATS
117117
mUsedRam -= mMaxNbEntries * sizeof(udword);
118118
#endif
119-
CFREE(mEntries);
119+
xr_free(mEntries);
120120
mCurNbEntries = mMaxNbEntries = 0;
121121
return *this;
122122
}

Externals/OPCODE/OPC_Model.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ OPCODE_Model::OPCODE_Model() : mSource(nullptr), mTree(nullptr), mNoLeaf(false),
170170
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
171171
OPCODE_Model::~OPCODE_Model()
172172
{
173-
CDELETE(mSource);
174-
CDELETE(mTree);
173+
xr_delete(mSource);
174+
xr_delete(mTree);
175175
#ifdef __MESHMERIZER_H__ // Collision hulls only supported within ICE !
176-
CDELETE(mHull);
176+
xr_delete(mHull);
177177
#endif // __MESHMERIZER_H__
178178
}
179179

@@ -212,7 +212,7 @@ bool OPCODE_Model::Build(const OPCODECREATE& create)
212212
// We continue nonetheless....
213213

214214
// 2) Build a generic AABB Tree.
215-
mSource = CNEW(AABBTree)();
215+
mSource = new AABBTree();
216216
CHECKALLOC(mSource);
217217

218218
// 2-1) Setup a builder. Our primitives here are triangles from input mesh,
@@ -233,16 +233,16 @@ bool OPCODE_Model::Build(const OPCODECREATE& create)
233233
if (mNoLeaf)
234234
{
235235
if (mQuantized)
236-
mTree = CNEW(AABBQuantizedNoLeafTree)();
236+
mTree = new AABBQuantizedNoLeafTree();
237237
else
238-
mTree = CNEW(AABBNoLeafTree)();
238+
mTree = new AABBNoLeafTree();
239239
}
240240
else
241241
{
242242
if (mQuantized)
243-
mTree = CNEW(AABBQuantizedTree)();
243+
mTree = new AABBQuantizedTree();
244244
else
245-
mTree = CNEW(AABBCollisionTree)();
245+
mTree = new AABBCollisionTree();
246246
}
247247

248248
// 3-2) Create optimized tree
@@ -253,15 +253,15 @@ bool OPCODE_Model::Build(const OPCODECREATE& create)
253253
if (!create.KeepOriginal)
254254
{
255255
mSource->destroy(&TB);
256-
CDELETE(mSource);
256+
xr_delete(mSource);
257257
}
258258

259259
#ifdef __MESHMERIZER_H__
260260
// 4) Convex hull
261261
if (create.CollisionHull)
262262
{
263263
// Create hull
264-
mHull = CNEW(CollisionHull)();
264+
mHull = new CollisionHull();
265265
CHECKALLOC(mHull);
266266

267267
CONVEXHULLCREATE CHC;

Externals/OPCODE/OPC_OptimizedTree.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ AABBCollisionTree::AABBCollisionTree() : mNodes(nullptr) {}
209209
* Destructor.
210210
*/
211211
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
212-
AABBCollisionTree::~AABBCollisionTree() { CFREE(mNodes); }
212+
AABBCollisionTree::~AABBCollisionTree() { xr_free(mNodes); }
213213
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
214214
/**
215215
* Builds the collision tree from a generic AABB tree.
@@ -230,7 +230,7 @@ bool AABBCollisionTree::Build(AABBTree* tree)
230230

231231
// Get nodes
232232
mNbNodes = NbNodes;
233-
mNodes = CALLOC(AABBCollisionNode, mNbNodes);
233+
mNodes = xr_alloc<AABBCollisionNode>(mNbNodes);
234234
CHECKALLOC(mNodes);
235235
ZeroMemory(mNodes, mNbNodes * sizeof(AABBCollisionNode));
236236

@@ -259,7 +259,7 @@ AABBNoLeafTree::AABBNoLeafTree() : mNodes(nullptr) {}
259259
* Destructor.
260260
*/
261261
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
262-
AABBNoLeafTree::~AABBNoLeafTree() { CFREE(mNodes); }
262+
AABBNoLeafTree::~AABBNoLeafTree() { xr_free(mNodes); }
263263
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
264264
/**
265265
* Builds the collision tree from a generic AABB tree.
@@ -280,7 +280,7 @@ bool AABBNoLeafTree::Build(AABBTree* tree)
280280

281281
// Get nodes
282282
mNbNodes = NbTriangles - 1;
283-
mNodes = CALLOC(AABBNoLeafNode, mNbNodes);
283+
mNodes = xr_alloc<AABBNoLeafNode>(mNbNodes);
284284
CHECKALLOC(mNodes);
285285
ZeroMemory(mNodes, mNbNodes * sizeof(AABBNoLeafNode));
286286

@@ -414,7 +414,7 @@ AABBQuantizedTree::AABBQuantizedTree() : mNodes(nullptr) {}
414414
* Destructor.
415415
*/
416416
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
417-
AABBQuantizedTree::~AABBQuantizedTree() { CFREE(mNodes); }
417+
AABBQuantizedTree::~AABBQuantizedTree() { xr_free(mNodes); }
418418
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
419419
/**
420420
* Builds the collision tree from a generic AABB tree.
@@ -435,7 +435,7 @@ bool AABBQuantizedTree::Build(AABBTree* tree)
435435

436436
// Get nodes
437437
mNbNodes = NbNodes;
438-
AABBCollisionNode* Nodes = CALLOC(AABBCollisionNode, mNbNodes);
438+
AABBCollisionNode* Nodes = xr_alloc<AABBCollisionNode>(mNbNodes);
439439
CHECKALLOC(Nodes);
440440
ZeroMemory(Nodes, mNbNodes * sizeof(AABBCollisionNode));
441441

@@ -445,7 +445,7 @@ bool AABBQuantizedTree::Build(AABBTree* tree)
445445

446446
// Quantize
447447
{
448-
mNodes = CALLOC(AABBQuantizedNode, mNbNodes);
448+
mNodes = xr_alloc<AABBQuantizedNode>(mNbNodes);
449449
CHECKALLOC(mNodes);
450450
ZeroMemory(mNodes, mNbNodes * sizeof(AABBQuantizedNode));
451451

@@ -463,7 +463,7 @@ bool AABBQuantizedTree::Build(AABBTree* tree)
463463
REMAP_DATA(mData)
464464
}
465465

466-
CFREE(Nodes);
466+
xr_free(Nodes);
467467
}
468468

469469
#ifdef __ICECORE_H__
@@ -485,7 +485,7 @@ AABBQuantizedNoLeafTree::AABBQuantizedNoLeafTree() : mNodes(nullptr) {}
485485
* Destructor.
486486
*/
487487
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
488-
AABBQuantizedNoLeafTree::~AABBQuantizedNoLeafTree() { CFREE(mNodes); }
488+
AABBQuantizedNoLeafTree::~AABBQuantizedNoLeafTree() { xr_free(mNodes); }
489489
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
490490
/**
491491
* Builds the collision tree from a generic AABB tree.
@@ -506,7 +506,7 @@ bool AABBQuantizedNoLeafTree::Build(AABBTree* tree)
506506

507507
// Get nodes
508508
mNbNodes = NbTriangles - 1;
509-
AABBNoLeafNode* Nodes = CALLOC(AABBNoLeafNode, mNbNodes);
509+
AABBNoLeafNode* Nodes = xr_alloc<AABBNoLeafNode>(mNbNodes);
510510
CHECKALLOC(Nodes);
511511
ZeroMemory(Nodes, mNbNodes * sizeof(AABBNoLeafNode));
512512

@@ -517,7 +517,7 @@ bool AABBQuantizedNoLeafTree::Build(AABBTree* tree)
517517

518518
// Quantize
519519
{
520-
mNodes = CALLOC(AABBQuantizedNoLeafNode, mNbNodes);
520+
mNodes = xr_alloc<AABBQuantizedNoLeafNode>(mNbNodes);
521521
CHECKALLOC(mNodes);
522522
ZeroMemory(mNodes, mNbNodes * sizeof(AABBQuantizedNoLeafNode));
523523

@@ -536,7 +536,7 @@ bool AABBQuantizedNoLeafTree::Build(AABBTree* tree)
536536
REMAP_DATA(mData2)
537537
}
538538

539-
CFREE(Nodes);
539+
xr_free(Nodes);
540540
}
541541

542542
#ifdef __ICECORE_H__

Externals/OPCODE/OPC_PlanesCollider.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ PlanesCollider::PlanesCollider() : mPlanes(nullptr), mNbPlanes(0) {}
6363
* Destructor.
6464
*/
6565
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
66-
PlanesCollider::~PlanesCollider() { CFREE(mPlanes); }
66+
PlanesCollider::~PlanesCollider() { xr_free(mPlanes); }
6767
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
6868
/**
6969
* Validates current settings. You should call this method after all the settings and callbacks have been defined.
@@ -140,8 +140,8 @@ BOOL PlanesCollider::InitQuery(PlanesCache& cache, const Plane* planes, udword n
140140
// 2) Compute planes in model space
141141
if (nb_planes > mNbPlanes)
142142
{
143-
CFREE(mPlanes);
144-
mPlanes = CALLOC(Plane, nb_planes);
143+
xr_free(mPlanes);
144+
mPlanes = xr_alloc<Plane>(nb_planes);
145145
}
146146
mNbPlanes = nb_planes;
147147

Externals/OPCODE/pch.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
11
#include "pch.hpp"
2-
3-
#ifdef USE_ARENA_ALLOCATOR
4-
static const u32 s_arena_size = (128 + 16) * 1024 * 1024;
5-
static char s_fake_array[s_arena_size];
6-
doug_lea_allocator g_collision_allocator(s_fake_array, s_arena_size, "opcode");
7-
#endif // #ifdef USE_ARENA_ALLOCATOR

Externals/OPCODE/pch.hpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,6 @@
11
#pragma once
22

33
#include <algorithm>
4-
54
#include "Common/Common.hpp"
65
#include "xrCore/xrCore.h"
7-
#include "xrCore/Memory/doug_lea_allocator.h"
8-
9-
#ifdef USE_ARENA_ALLOCATOR
10-
extern doug_lea_allocator g_collision_allocator;
11-
12-
#define CNEW(type) new (g_collision_allocator.alloc_impl<type>(1)) type
13-
#define CDELETE(ptr) cdelete(ptr)
14-
#define CFREE(ptr) g_collision_allocator.free_impl(ptr)
15-
#define CMALLOC(size) g_collision_allocator.malloc_impl(size)
16-
#define CALLOC(type, count) g_collision_allocator.alloc_impl<type>(count)
17-
#else // #ifdef USE_ARENA_ALLOCATOR
18-
#define CNEW(type) new (xr_alloc<type>(1)) type
19-
#define CDELETE(ptr) xr_delete(ptr)
20-
#define CFREE(ptr) xr_free(ptr)
21-
#define CMALLOC(size) xr_malloc(size)
22-
#define CALLOC(type, count) xr_alloc<type>(count)
23-
#endif // #ifdef USE_ARENA_ALLOCATOR
24-
25-
template <bool _is_pm, typename T>
26-
struct cspecial_free
27-
{
28-
IC void operator()(T*& ptr)
29-
{
30-
void* _real_ptr = dynamic_cast<void*>(ptr);
31-
ptr->~T();
32-
CFREE(_real_ptr);
33-
}
34-
};
35-
36-
template <typename T>
37-
struct cspecial_free<false, T>
38-
{
39-
IC void operator()(T*& ptr)
40-
{
41-
ptr->~T();
42-
CFREE(ptr);
43-
}
44-
};
45-
46-
template <class T>
47-
IC void cdelete(T*& ptr)
48-
{
49-
if (ptr)
50-
{
51-
cspecial_free<std::is_polymorphic<T>::value, T>()(ptr);
52-
ptr = NULL;
53-
}
54-
}
55-
566
#include "Opcode.h"

src/Layers/xrRender/D3DXRenderBase.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ class D3DXRenderBase : public IRender, public pureFrame
138138
void r_dsgraph_render_subspace(
139139
IRender_Sector* _sector, Fmatrix& mCombined, Fvector& _cop, BOOL _dynamic, BOOL _precise_portals = FALSE);
140140
void r_dsgraph_render_R1_box(IRender_Sector* _sector, Fbox& _bb, int _element);
141-
virtual u32 memory_usage() override { return g_render_allocator.get_allocated_size(); }
142141
virtual void Copy(IRender& _in) override;
143142
// Gamma correction functions
144143
virtual void setGamma(float fGamma) override;

src/xrCDB/StdAfx.h

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,4 @@
22

33
#include "Common/Common.hpp"
44
#include "xrCore/xrCore.h"
5-
#include "xrCore/Memory/doug_lea_allocator.h"
6-
7-
#ifdef USE_ARENA_ALLOCATOR
8-
extern doug_lea_allocator g_collision_allocator;
9-
10-
#define CNEW(type) new (g_collision_allocator.alloc_impl<type>(1)) type
11-
#define CDELETE(ptr) cdelete(ptr)
12-
#define CFREE(ptr) g_collision_allocator.free_impl(ptr)
13-
#define CMALLOC(size) g_collision_allocator.malloc_impl(size)
14-
#define CALLOC(type, count) g_collision_allocator.alloc_impl<type>(count)
15-
#else // #ifdef USE_ARENA_ALLOCATOR
16-
#define CNEW(type) new (xr_alloc<type>(1)) type
17-
#define CDELETE(ptr) xr_delete(ptr)
18-
#define CFREE(ptr) xr_free(ptr)
19-
#define CMALLOC(size) xr_malloc(size)
20-
#define CALLOC(type, count) xr_alloc<type>(count)
21-
#endif // #ifdef USE_ARENA_ALLOCATOR
22-
23-
template <bool _is_pm, typename T>
24-
struct cspecial_free
25-
{
26-
IC void operator()(T*& ptr)
27-
{
28-
void* _real_ptr = dynamic_cast<void*>(ptr);
29-
ptr->~T();
30-
CFREE(_real_ptr);
31-
}
32-
};
33-
34-
template <typename T>
35-
struct cspecial_free<false, T>
36-
{
37-
IC void operator()(T*& ptr)
38-
{
39-
ptr->~T();
40-
CFREE(ptr);
41-
}
42-
};
43-
44-
template <class T>
45-
IC void cdelete(T*& ptr)
46-
{
47-
if (ptr)
48-
{
49-
cspecial_free<std::is_polymorphic<T>::value, T>()(ptr);
50-
ptr = NULL;
51-
}
52-
}
53-
545
#include "OPCODE/Opcode.h"
55-
56-
//{{AFX_INSERT_LOCATION}}
57-
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

0 commit comments

Comments
 (0)