CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
ChunkAllocator.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, Open Design Alliance (the "Alliance").
3// All rights reserved.
4//
5// This software and its documentation and related materials are owned by
6// the Alliance. The software may only be incorporated into application
7// programs owned by members of the Alliance, subject to a signed
8// Membership Agreement and Supplemental Software License Agreement with the
9// Alliance. The structure and organization of this software are the valuable
10// trade secrets of the Alliance and its suppliers. The software is also
11// protected by copyright law and international treaty provisions. Application
12// programs incorporating this software must include the following statement
13// with their copyright notices:
14//
15// This application incorporates Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 by Open Design Alliance.
18// All rights reserved.
19//
20// By use of this software, its documentation or related materials, you
21// acknowledge and accept the above terms.
23
24#ifndef __CHUNK_ALLOCATOR__
25#define __CHUNK_ALLOCATOR__
26
27#include "RootExport.h"
28#include "RxObjectImpl.h"
29
30#include "TD_PackPush.h"
31
36{
37public:
38 virtual void* alloc(int) = 0;
39 virtual void release(void* p) = 0;
40 virtual ~IAllocator() {}
41
43#ifdef _DEBUG
44 virtual int numChunks() = 0;
45#endif
46};
47
52{
53public:
54 //'mask' is a bit flags value, each bit represents
55 // enhancedForFixedSize flag per item.
56 // If size > sizeof(mask) then the rest items have the flag '0'
57 AllocatorArray(unsigned size, int mask);
59
60 unsigned size() const { return m_size; }
61 IAllocator* getAt(unsigned i)
62 {
63 ODA_ASSERT(i < m_size);
64 return m_data[i];
65 }
66
67protected:
69 unsigned m_size;
70};
71
72FIRSTDLL_EXPORT void addLocalHeaps(unsigned nThreadId, const unsigned* aThreadId);
73FIRSTDLL_EXPORT void releaseLocalHeaps(unsigned nThreadId, const unsigned* aThreadId);
74
75// Prevent MFC memleaks displaying
76
81{
82 protected:
84 unsigned m_origSize;
86
87 void clear()
88 {
89 m_bAllocated = false;
90 m_data = NULL;
91 m_size = 0;
92 }
93 public:
94 AllocatorArrayML(unsigned size, int mask)
97 { }
99 void reset()
100 {
101 if (!m_bAllocated)
102 {
104 *this = tmp;
105 tmp.clear();
106 }
107 }
108 void uninit()
109 {
110 if (m_bAllocated) {
111 this->~AllocatorArrayML();
112 clear();
113 }
114 }
115};
116
117// Some simplifiers for allocator specification
118
119#define ODCA_HEAP_OPERATORS() \
120 void* operator new(size_t); \
121 void operator delete(void*)
122
123#define ODCA_HEAP_ALLOCATOR() \
124 static AllocatorArrayML s_aAlloc
125
126#define ODCA_HEAP_OPERATORS_DEFINE(baseClass, num) \
127 void* baseClass::operator new(size_t size) \
128 { \
129 return s_aAlloc.getAt(num)->alloc((int)size); \
130 } \
131 void baseClass::operator delete(void* p) \
132 { \
133 s_aAlloc.getAt(num)->release(p); \
134 }
135
136#define ODCA_HEAP_OPERATORS_DEFINE_0(baseClass) \
137 ODCA_HEAP_OPERATORS_DEFINE(baseClass, 0)
138
139#define ODCA_HEAP_ALLOCATOR_DEFINE(baseClass, numAllocs, allocMask) \
140 AllocatorArrayML baseClass::s_aAlloc(numAllocs, allocMask)
141
142#define ODCA_HEAP_ALLOCATOR_DEFINE_1(baseClass) \
143 ODCA_HEAP_ALLOCATOR_DEFINE(baseClass, 1, 0)
144#define ODCA_HEAP_ALLOCATOR_DEFINE_1_ENH(baseClass) \
145 ODCA_HEAP_ALLOCATOR_DEFINE(baseClass, 1, 1)
146
147#define ODCA_HEAP_ALLOCATOR_RESET(baseClass) \
148 baseClass::s_aAlloc.reset()
149#define ODCA_HEAP_ALLOCATOR_UNINIT(baseClass) \
150 baseClass::s_aAlloc.uninit()
151
155template<class T, class TInterface = T>
156class OdGiRxObjectReImpl : public OdRxObjectImpl<T, TInterface>
157{
161 OdGiRxObjectReImpl& operator = (const OdGiRxObjectReImpl&) { return *this; }
162
163 protected:
164 void* operator new (size_t size) { return T::operator new (size); }
165 void operator delete (void* p) { T::operator delete (p); }
166
167 public:
173 {
174 return OdSmartPtr<TInterface>(static_cast<TInterface*>(new OdGiRxObjectReImpl<T, TInterface>), kOdRxObjAttach);
175 }
176};
177
178#define GIRXREIMPL_CONSTR(ClassName) OdGiRxObjectReImpl<ClassName>::createObject()
179
180#include "TD_PackPop.h"
181
182#endif // __CHUNK_ALLOCATOR__
FIRSTDLL_EXPORT void releaseLocalHeaps(unsigned nThreadId, const unsigned *aThreadId)
FIRSTDLL_EXPORT void addLocalHeaps(unsigned nThreadId, const unsigned *aThreadId)
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:57
true
Definition: DimVarDefs.h:2046
#define FIRSTDLL_EXPORT
Definition: RootExport.h:39
@ kOdRxObjAttach
Definition: RxObject.h:56
IAllocator ** m_data
AllocatorArray(unsigned size, int mask)
IAllocator * getAt(unsigned i)
unsigned size() const
AllocatorArrayML(unsigned size, int mask)
virtual ~IAllocator()
virtual void release(void *p)=0
virtual void * alloc(int)=0
static OdSmartPtr< TInterface > createObject()
GLsizeiptr size
Definition: gles2_ext.h:182
GLenum GLint GLuint mask
Definition: gles2_ext.h:262