31 #ifndef __BypassAllocator__ 32 #define __BypassAllocator__ 40 #include "MemoryUtils.h" 54 typedef const T* const_pointer;
56 typedef const T& const_reference;
57 typedef size_t size_type;
58 typedef ptrdiff_t difference_type;
67 pointer address (reference value)
const {
70 const_pointer address (const_reference value)
const {
88 size_type max_size () const noexcept {
89 return (size_type) (int64) -1 /
sizeof(T);
93 pointer allocate (size_type num,
const void* = 0) {
95 pointer ret = (pointer)
new char[num *
sizeof(T)];
97 #if defined(MACINTOSH) && defined(DEBUG) 98 pointer ret = (pointer) K2Memory::RTLCompatibleBypassMalloc (num *
sizeof(T));
100 pointer ret = (pointer) malloc (num *
sizeof(T));
102 if (!ret)
throw std::bad_alloc();
108 void construct (pointer p,
const T& value) {
110 new((
void*)p)T(value);
114 void destroy (pointer p) {
120 void deallocate (pointer p, size_type num) {
123 #elif defined(MACINTOSH) && defined(DEBUG) 124 K2Memory::RTLCompatibleBypassFree (p);
133 template <
class T1,
class T2>
137 template <
class T1,
class T2>
153 typedef T value_type;
155 typedef const T* const_pointer;
156 typedef T& reference;
157 typedef const T& const_reference;
158 typedef size_t size_type;
159 typedef ptrdiff_t difference_type;
168 pointer address (reference value)
const {
171 const_pointer address (const_reference value)
const {
186 #if defined(MACINTOSH) && defined(DEBUG) 187 K2Memory::RTLCompatibleBypassFree (fStack [--fSP]);
189 free (fStack [--fSP]);
194 size_type max_size () const noexcept {
195 return (size_type) (int64) -1 /
sizeof(T);
199 pointer allocate (size_type num,
const void* = 0) {
200 if (num == 1 && fSP)
return fStack [--fSP];
201 #if defined(MACINTOSH) && defined(DEBUG) 202 pointer ret = (pointer) K2Memory::RTLCompatibleBypassMalloc (num *
sizeof(T));
204 pointer ret = (pointer) malloc (num *
sizeof(T));
206 if (!ret)
throw std::bad_alloc();
211 void construct (pointer p,
const T& value) {
213 new((
void*)p)T(value);
217 void destroy (pointer p) {
223 void deallocate (pointer p, size_type num) {
224 if (num == 1 && fSP < kMaxSize)
227 #if defined(MACINTOSH) && defined(DEBUG) 228 K2Memory::RTLCompatibleBypassFree (p);
236 enum { kMaxSize = 1000 };
237 pointer fStack [kMaxSize];
241 template <
class T1,
class T2>
245 template <
class T1,
class T2>
262 typedef T value_type;
264 typedef const T* const_pointer;
265 typedef T& reference;
266 typedef const T& const_reference;
267 typedef size_t size_type;
268 typedef ptrdiff_t difference_type;
277 pointer address (reference value)
const {
280 const_pointer address (const_reference value)
const {
294 size_type max_size () const noexcept {
295 return (size_type) (int64) -1 /
sizeof(T);
299 pointer allocate (size_type num,
const void* = 0) {
300 pointer ret = (pointer) K2Memory::RTLCompatibleMallocNoPurging (num *
sizeof(value_type));
301 if (!ret)
throw std::bad_alloc();
306 void construct (pointer p,
const T& value) {
308 new((
void*)p)value_type(value);
312 void destroy (pointer p) {
318 void deallocate (pointer p, size_type num) {
319 K2Memory::RTLCompatibleFree(p);
325 template <
class T1,
class T2>
329 template <
class T1,
class T2>
335 #endif // __BypassAllocator__