HeapzoneAllocator.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
5 | Copyright (c) 2018 Bentley Systems, Incorporated. All rights reserved.
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9 
10 // We include bentley and exportmacros because EC source files include HeapzoneAllocator.h as the first include
11 #include <Bentley/Bentley.h>
12 #include <RmgrTools/ExportMacros.h>
13 #include <Bentley/bset.h>
14 
15 #include <limits>
16 
17 #define STD_SET_W_STATIC_HEAPZONE(_Vt)\
18  bset< _Vt,\
19  std::less<_Vt>, 32,\
20  ::Bentley::Memory::HeapzoneAllocator< _Vt >\
21  >
22 
23 #define STD_SET_W_STATIC_HEAPZONE_EX(_Vt,_Cmp)\
24  bset< _Vt,\
25  _Cmp,32,\
26  ::Bentley::Memory::HeapzoneAllocator< _Vt >\
27  >
28 
29 #define STD_MULTISET_W_STATIC_HEAPZONE_EX(_Vt,_Cmp)\
30  std::multiset< _Vt,\
31  _Cmp, \
32  ::Bentley::Memory::HeapzoneAllocator< _Vt >\
33  >
34 
35 
36 #define STD_MAP_W_STATIC_HEAPZONE(_Kt,_Vt)\
37  bmap< _Kt,\
38  _Vt,\
39  std::less<_Kt>,32,\
40  ::Bentley::Memory::HeapzoneAllocator< bpair<const _Kt, _Vt> >\
41  >
42 
43 #define STD_MAP_W_STATIC_HEAPZONE_EX(_Kt,_Vt,_Cmp)\
44  bmap< _Kt,\
45  _Vt,\
46  _Cmp,32,\
47  ::Bentley::Memory::HeapzoneAllocator< bpair<const _Kt, _Vt> >\
48  >
49 
50 #define STD_LIST_W_STATIC_HEAPZONE(_Vt)\
51  std::list< _Vt,\
52  ::Bentley::Memory::HeapzoneAllocator< _Vt >\
53  >
54 
60 
61 namespace Memory {
62 
63 /*=================================================================================**/
77 template <class T>
79  {
80 public:
81  // type definitions
82  typedef T value_type;
83  typedef T* pointer;
84  typedef const T* const_pointer;
85  typedef T& reference;
86  typedef const T& const_reference;
87  typedef std::size_t size_type;
88  typedef std::ptrdiff_t difference_type;
89 
90  // rebind allocator to type U
91  template <class U>
92  struct rebind
93  {
95  };
96 
97  // return address of values
98  pointer address (reference value) const
99  {
100  return &value;
101  }
102 
104  {
105  return &value;
106  }
107 
108  /* constructors and destructor
109  */
111  {
112  }
113 
115  {
116  }
117 
118  template <class U>
120  {
121  }
122 
124  {
125  }
126 
127  // return maximum number of elements that can be allocated
128  size_type max_size () const throw()
129  {
130  // *** BENTLEY MODIFICATION ***
131  //return std::numeric_limits<std::size_t>::max() / sizeof(T); *** avoid conflict with macro "max"
132  size_type _Count = (size_type)(-1) / sizeof (T);
133  return (0 < _Count ? _Count : 1);
134  }
135 
136  // allocate but don't initialize num elements of type T
137  pointer allocate (size_type num, const void* = 0)
138  {
139  // *** BENTLEY MODIFICATION ***
140  return (pointer) toolSubsystem_allocSmallBlock (num * sizeof (T));
141  }
142 
143  // initialize elements of allocated storage p with value value
144  void construct (pointer p, const T& value)
145  {
146  // initialize memory with placement new
147  new((void*)p)T(value);
148  }
149 
150  // destroy elements of initialized storage p
151  void destroy (pointer p)
152  {
153  // destroy objects by calling their destructor
154  p->~T();
155  }
156 
157  // deallocate storage p of deleted elements
159  {
160  // *** BENTLEY MODIFICATION ***
161  toolSubsystem_freeSmallBlock (p, num * sizeof (T));
162  }
163  };
164 
165 // return that all specializations of this allocator are interchangeable
166 template <class T1, class T2>
168  const HeapzoneAllocator<T2>&) throw()
169  {
170  return true;
171  }
172 
173 template <class T1, class T2>
175  const HeapzoneAllocator<T2>&) throw()
176  {
177  return false;
178  }
179 
180 } // namespace Memory
182 
Definition: HeapzoneAllocator.h:92
void construct(pointer p, const T &value)
Definition: HeapzoneAllocator.h:144
RMGRSUBS_EXPORT void toolSubsystem_freeSmallBlock(void *, size_t)
Provides Bentley specific set implementation (Bentley/bset.h).
HeapzoneAllocator(const HeapzoneAllocator< U > &cc)
Definition: HeapzoneAllocator.h:119
HeapzoneAllocator(const HeapzoneAllocator &cc)
Definition: HeapzoneAllocator.h:114
bool operator==(const HeapzoneAllocator< T1 > &, const HeapzoneAllocator< T2 > &)
Definition: HeapzoneAllocator.h:167
const_pointer address(const_reference value) const
Definition: HeapzoneAllocator.h:103
void destroy(pointer p)
Definition: HeapzoneAllocator.h:151
Allocates memory from the DgnPlatform small block heap.
Definition: HeapzoneAllocator.h:78
bool operator!=(const HeapzoneAllocator< T1 > &, const HeapzoneAllocator< T2 > &)
Definition: HeapzoneAllocator.h:174
T * pointer
Definition: HeapzoneAllocator.h:83
T & reference
Definition: HeapzoneAllocator.h:85
const T & const_reference
Definition: HeapzoneAllocator.h:86
const T * const_pointer
Definition: HeapzoneAllocator.h:84
#define RMGRSUBS_EXPORT
Definition: DgnPlatform/ExportMacros.h:70
#define BEGIN_BENTLEY_NAMESPACE
Definition: Bentley.r.h:24
pointer allocate(size_type num, const void *=0)
Definition: HeapzoneAllocator.h:137
~HeapzoneAllocator()
Definition: HeapzoneAllocator.h:123
size_type max_size() const
Definition: HeapzoneAllocator.h:128
RMGRSUBS_EXPORT void * toolSubsystem_allocSmallBlock(size_t)
Defines typedefs and constants that can be used across other namespaces. All Bentley-authored C++ sou...
T value_type
Definition: HeapzoneAllocator.h:82
HeapzoneAllocator()
Definition: HeapzoneAllocator.h:110
#define END_BENTLEY_NAMESPACE
Definition: Bentley.r.h:25
pointer address(reference value) const
Definition: HeapzoneAllocator.h:98
std::size_t size_type
Definition: HeapzoneAllocator.h:87
std::ptrdiff_t difference_type
Definition: HeapzoneAllocator.h:88
void deallocate(pointer p, size_type num)
Definition: HeapzoneAllocator.h:158
HeapzoneAllocator< U > other
Definition: HeapzoneAllocator.h:94

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.