CFx SDK Documentation  2020SP3
ChunkAllocator.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, 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 Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 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 {
37 public:
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 {
53 public:
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 
67 protected:
69  unsigned m_size;
70 };
71 
72 FIRSTDLL_EXPORT void addLocalHeaps(unsigned nThreadId, const unsigned* aThreadId);
73 FIRSTDLL_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 
155 template<class T, class TInterface = T>
156 class 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
#define FIRSTDLL_EXPORT
Definition: RootExport.h:39
NULL
#define NULL
Definition: GsProperties.h:177
OdGiRxObjectReImpl
Definition: ChunkAllocator.h:157
AllocatorArrayML::m_bAllocated
bool m_bAllocated
Definition: ChunkAllocator.h:83
AllocatorArrayML::AllocatorArrayML
AllocatorArrayML(unsigned size, int mask)
Definition: ChunkAllocator.h:94
AllocatorArray::m_size
unsigned m_size
Definition: ChunkAllocator.h:69
AllocatorArray::size
unsigned size() const
Definition: ChunkAllocator.h:60
TD_PackPop.h
IAllocator::alloc
virtual void * alloc(int)=0
AllocatorArrayML::reset
void reset()
Definition: ChunkAllocator.h:99
AllocatorArray
Definition: ChunkAllocator.h:52
releaseLocalHeaps
FIRSTDLL_EXPORT void releaseLocalHeaps(unsigned nThreadId, const unsigned *aThreadId)
mask
GLenum GLint GLuint mask
Definition: gles2_ext.h:262
size
GLsizeiptr size
Definition: gles2_ext.h:182
AllocatorArrayML::~AllocatorArrayML
~AllocatorArrayML()
Definition: ChunkAllocator.h:98
AllocatorArrayML::uninit
void uninit()
Definition: ChunkAllocator.h:108
AllocatorArrayML::m_origMask
int m_origMask
Definition: ChunkAllocator.h:85
IAllocator::~IAllocator
virtual ~IAllocator()
Definition: ChunkAllocator.h:40
RootExport.h
OdSmartPtr
Definition: SmartPtr.h:58
true
true
Definition: DimVarDefs.h:2046
AllocatorArray::~AllocatorArray
~AllocatorArray()
AllocatorArray::m_data
IAllocator ** m_data
Definition: ChunkAllocator.h:68
addLocalHeaps
FIRSTDLL_EXPORT void addLocalHeaps(unsigned nThreadId, const unsigned *aThreadId)
IAllocator::IAllocator
IAllocator()
TD_PackPush.h
AllocatorArrayML::clear
void clear()
Definition: ChunkAllocator.h:87
OdGiRxObjectReImpl::createObject
static OdSmartPtr< TInterface > createObject()
Definition: ChunkAllocator.h:172
IAllocator
Definition: ChunkAllocator.h:36
AllocatorArray::AllocatorArray
AllocatorArray(unsigned size, int mask)
ODA_ASSERT
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:49
kOdRxObjAttach
@ kOdRxObjAttach
Definition: RxObject.h:56
AllocatorArrayML::m_origSize
unsigned m_origSize
Definition: ChunkAllocator.h:84
OdRxObjectImpl
Definition: RxObjectImpl.h:55
IAllocator::release
virtual void release(void *p)=0
RxObjectImpl.h
AllocatorArrayML
Definition: ChunkAllocator.h:81
AllocatorArray::getAt
IAllocator * getAt(unsigned i)
Definition: ChunkAllocator.h:61