This repository has been archived by the owner on May 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathallocators
907 lines (781 loc) · 20.4 KB
/
allocators
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
// allocators extension header
#pragma once
#ifndef _ALLOCATORS_
#define _ALLOCATORS_
#ifndef RC_INVOKED
#include <new>
#include <xutility>
#include <stddef.h>
#pragma pack(push,_CRT_PACKING)
#pragma warning(push,3)
#pragma push_macro("new")
#undef new
#if !defined(_DECLSPEC_ALLOCATOR)
#if 1900 <= _MSC_VER && !defined(__EDG__)
#define _DECLSPEC_ALLOCATOR __declspec(allocator)
#else /* 1900 <= _MSC_VER, etc. */
#define _DECLSPEC_ALLOCATOR
#endif /* 1900 <= _MSC_VER, etc. */
#endif /* !defined(_DECLSPEC_ALLOCATOR) */
#if !defined(_ALLOCATORS_NO_REBIND)
#define _ALLOCATORS_NO_REBIND 0
#endif /* !defined(_ALLOCATORS_NO_REBIND) */
#if !defined(_HAS_ALLOCATORS_IN_STD)
#define _HAS_ALLOCATORS_IN_STD 0
#endif /* !defined(_HAS_ALLOCATORS_IN_STD) */
namespace stdext {
namespace threads { // MINITHREADS
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Mtx_new(void *&);
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Mtx_delete(void *);
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Mtx_lock(void *);
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Mtx_unlock(void *);
class mutex
{
public:
friend class _Scoped_lock;
typedef _Scoped_lock scoped_lock;
mutex()
: _Ptr(0)
{
_Mtx_new(_Ptr);
}
~mutex() _NOEXCEPT
{
_Mtx_delete(_Ptr);
}
private:
mutex(const mutex&);
mutex& operator=(const mutex&);
void * _Ptr;
};
class _Scoped_lock
{
public:
explicit _Scoped_lock(mutex& _Mut)
: _Ptr(_Mut._Ptr)
{
_Mtx_lock(_Ptr);
}
~_Scoped_lock() _NOEXCEPT
{
_Mtx_unlock(_Ptr);
}
private:
_Scoped_lock(const _Scoped_lock&);
_Scoped_lock& operator=(const _Scoped_lock&);
void * _Ptr;
};
} // namespace threads
} // namespace stdext
namespace stdext {
namespace allocators {
// SYNCHRONIZATION FILTERS
template<class _Cache>
class sync_none
{ // cache with no synchronization
public:
_DECLSPEC_ALLOCATOR void *allocate(size_t _Count)
{ // allocate from the cache
return (_Mycache.allocate(_Count));
}
void deallocate(void *_Ptr, size_t _Count)
{ // deallocate through the cache
_Mycache.deallocate(_Ptr, _Count);
}
bool equals(const sync_none<_Cache>& _Other) const
{ // compare two caches for equality
return (_Mycache.equals(_Other._Mycache));
}
private:
static _Cache _Mycache;
};
template<class _Cache>
_Cache sync_none<_Cache>::_Mycache;
template<class _Cache>
class sync_per_container
: public _Cache
{ // cache with per-container synchronization
public:
bool equals(const sync_per_container<_Cache>&) const
{ // per-container allocators never share memory blocks
return (false);
}
};
#define SYNC_DEFAULT stdext::allocators::sync_shared
template<class _Cache>
class sync_shared
{ // cache with shared synchronization
public:
_DECLSPEC_ALLOCATOR void *allocate(size_t _Count)
{ // allocate from the cache
threads::mutex::scoped_lock lock(_Mymtx);
return (_Mycache.allocate(_Count));
}
void deallocate(void *_Ptr, size_t _Count)
{ // deallocate through the cache
threads::mutex::scoped_lock lock(_Mymtx);
_Mycache.deallocate(_Ptr, _Count);
}
bool equals(const sync_shared<_Cache>& _Other) const
{ // compare two caches for equality
return (_Mycache.equals(_Other._Mycache));
}
private:
static _Cache _Mycache;
static threads::mutex _Mymtx;
};
template<class _Cache>
_Cache sync_shared<_Cache>::_Mycache;
template<class _Cache>
threads::mutex sync_shared<_Cache>::_Mymtx;
template<class _Cache>
class sync_per_thread
{ // cache with per-thread synchronization
public:
_DECLSPEC_ALLOCATOR void *allocate(size_t _Count)
{ // allocate from cache
if (_Mycache_ptr == 0)
_Mycache_ptr = new _Cache();
return (_Mycache_ptr != 0 ? _Mycache_ptr->allocate(_Count) : 0);
}
void deallocate(void *_Ptr, size_t _Count)
{ // deallocate through cache
if (_Mycache_ptr != 0)
_Mycache_ptr->deallocate(_Ptr, _Count);
}
bool equals(const sync_per_thread<_Cache>& _Other) const
{ // compare two caches for equality
return (_Mycache_ptr != 0
&& _Other._Mycache_ptr != 0
&& _Mycache_ptr->equals(*_Other._Mycache_ptr));
}
private:
static __declspec(thread) _Cache * _Mycache_ptr;
};
template<class _Cache>
__declspec(thread) _Cache *
sync_per_thread<_Cache>::_Mycache_ptr;
// MAX CLASSES AND TEMPLATES
class max_none
{ // max class for no caching
public:
bool full() const
{ // always full
return (true);
}
void saved()
{ // do nothing
}
void released()
{ // do nothing
}
void allocated(size_t = 1)
{ // do nothing
}
void deallocated(size_t = 1)
{ // do nothing
}
};
class max_unbounded
{ // max class for free list with unlimited size
public:
bool full() const
{ // never full
return (false);
}
void saved()
{ // do nothing
}
void released()
{ // do nothing
}
void allocated(size_t = 1)
{ // do nothing
}
void deallocated(size_t = 1)
{ // do nothing
}
};
template<size_t _Max>
class max_fixed_size
{ // max class for free list with fixed size
public:
max_fixed_size()
: _Nblocks(0)
{ // construct with no blocks
}
bool full() const
{ // test for full
return (_Max <= _Nblocks);
}
void saved()
{ // increment saved count
++_Nblocks;
}
void released()
{ // decrement saved count
--_Nblocks;
}
void allocated(size_t = 1)
{ // do nothing
}
void deallocated(size_t = 1)
{ // do nothing
}
private:
unsigned long _Nblocks;
};
class max_variable_size
{ // max class for free list with size proportional to allocations
public:
max_variable_size()
: _Nblocks(0), _Nallocs(0)
{ // construct with no blocks or allocations
}
bool full() const
{ // test for full
return (_Nallocs / 16 + 16 <= _Nblocks);
}
void saved()
{ // increment saved count
++_Nblocks;
}
void released()
{ // decrement saved count
--_Nblocks;
}
void allocated(size_t _Nx = 1)
{ // increment allocated count
_Nallocs = (unsigned long)(_Nallocs + _Nx);
}
void deallocated(size_t _Nx = 1)
{ // decrement allocated count
_Nallocs = (unsigned long)(_Nallocs - _Nx);
}
private:
unsigned long _Nblocks;
unsigned long _Nallocs;
};
// CACHES
template<size_t _Sz,
class _Max>
class freelist
: public _Max
{ // class for basic free list logic
public:
freelist()
: _Head(0)
{ // construct with empty list
}
bool push(void *_Ptr)
{ // push onto free list depending on max
if (this->full())
return (false);
else
{ // push onto free list
((node*)_Ptr)->_Next = _Head;
_Head = (node*)_Ptr;
this->saved();
return (true);
}
}
void *pop()
{ // pop node from free list
void *_Ptr = _Head;
if (_Ptr != 0)
{ // relink
_Head = _Head->_Next;
this->released();
}
return (_Ptr);
}
private:
struct node
{ // list node
node *_Next;
};
node *_Head;
};
template<size_t _Sz,
class _Max>
class cache_freelist
{ // class for allocating from free store and caching in free list
public:
~cache_freelist() _NOEXCEPT
{ // destroy the list
void *_Ptr;
while ((_Ptr = _Fl.pop()) != 0)
::operator delete(_Ptr);
}
_DECLSPEC_ALLOCATOR void *allocate(size_t _Count)
{ // pop from free list or allocate from free store
void *_Res = _Fl.pop();
if (_Res == 0)
{ // free list empty, allocate from free store
if (_Count < sizeof (void *))
_Res = ::operator new(sizeof (void *));
else
_Res = ::operator new(_Count);
_Fl.allocated();
}
return (_Res);
}
void deallocate(void *_Ptr, size_t)
{ // push onto free list or deallocate to free store
if (!_Fl.push(_Ptr))
{ // free list full, deallocate to free store
::operator delete(_Ptr);
_Fl.deallocated();
}
}
bool equals(const cache_freelist<_Sz, _Max>&) const
{ // report that caches can share data
return (true);
}
private:
freelist<_Sz, _Max> _Fl;
};
template<size_t _Sz,
size_t _Nelts = 20>
class cache_suballoc
{ // suballocate without reblocking
// NB: THIS CLASS INTENTIONALLY DOES *NOT* FREE STORAGE
public:
cache_suballoc()
: _Begin(0), _End(0)
{ // construct with empty list
}
_DECLSPEC_ALLOCATOR void *allocate(size_t _Count)
{ // pop from free list or suballocate
void *_Res = _Helper.pop();
if (_Res == 0)
{ // free list empty, suballocate
if (_Begin == _End)
{ // no room in block, allocate new block
if (_Count * _Nelts < sizeof (void *))
_Begin = (char*)::operator new(sizeof (void *));
else
_Begin = (char*)::operator new(_Count * _Nelts);
_End = _Begin + _Count * _Nelts;
_Helper.allocated(_Nelts);
}
_Res = _Begin;
_Begin += _Count;
}
return (_Res);
}
void deallocate(void *_Ptr, size_t)
{ // push onto free list
_Helper.push(_Ptr);
}
bool equals(const cache_suballoc<_Sz, _Nelts>&) const
{ // report that caches can share data
return (true);
}
private:
freelist<_Sz, max_unbounded> _Helper;
char *_Begin;
char *_End;
};
template<size_t _Sz,
size_t _Nelts = 20>
class cache_chunklist
{ // suballocate with reblocking
public:
cache_chunklist()
: _List(0), _Cached_block(0)
{ // construct with empty list
}
~cache_chunklist() _NOEXCEPT
{ // discard any cached block
delete _Cached_block;
}
_DECLSPEC_ALLOCATOR void *allocate(size_t _Count)
{ // suballocate
if (_List == 0)
{ // no list, allocate new item
_List = new _Data_block(_Count);
_List->_Next = _List->_Prev = _List;
}
else if (_List->_Free_count == 0)
{ // list empty, return cached or allocate
_Data_block *_Block;
if (_Cached_block != 0)
{ // return cached
_Block = _Cached_block;
_Cached_block = 0;
}
else
_Block = new _Data_block(_Count);
_Block->_Next = _List->_Next;
_Block->_Prev = _List;
_Block->_Next->_Prev = _Block;
_Block->_Prev->_Next = _Block;
_List = _Block;
}
void *_Res = _List->allocate();
if (_List->_Free_count == 0 && _List->_Next != _List)
{ // unlink head block with no available nodes
_List->_Next->_Prev = _List->_Prev;
_List->_Prev->_Next = _List->_Next;
_List = _List->_Next;
}
return (_Res);
}
void deallocate(void *_Ptr, size_t)
{ // deallocate node
_Data_block *_Block = _Data_block::deallocate(_Ptr);
if (_Block == _List->_Prev)
;
else if (_Block->_Free_count == 1)
{ // insert master block before tail block
_Data_block *tail = _List->_Prev;
tail->_Prev->_Next = _Block;
_Block->_Prev = tail->_Prev;
tail->_Prev = _Block;
_Block->_Next = tail;
if (_List->_Free_count == 0)
_List = _List->_Next;
}
else if (_Block->_Free_count == _Nelts)
{ // unlink and deallocate master block
_Block->_Next->_Prev = _Block->_Prev;
_Block->_Prev->_Next = _Block->_Next;
if (_List == _Block)
_List = _List->_Next;
if (_Cached_block == 0)
_Cached_block = _Block;
}
}
bool equals(const cache_chunklist<_Sz, _Nelts>&) const
{ // report that caches can share data
return (true);
}
private:
class _Data_block;
struct _Data_node
{ // memory block with pointer to parent
_Data_block *_Parent;
union
{ // ensure sufficient size
_Data_node *_Next;
char _Data[_Sz];
};
};
#if _ALLOCATORS_NO_REBIND
class _Data_array
{ // manage array of data
public:
_Data_array(size_t _Count)
{ // construct with _Count elements
_Size = _Count;
_Elts = (_Data_node*)::operator new(
(offsetof(_Data_node, _Data) + _Size) * _Nelts);
}
~_Data_array() _NOEXCEPT
{ // destroy the array
::operator delete(_Elts);
}
_Data_node& operator[](int _Idx)
{ // get reference to idx element
return (*(_Data_node*)((char*)_Elts + _Idx
* (offsetof(_Data_node, _Data) + _Size)));
}
private:
_Data_node *_Elts;
size_t _Size;
};
#else /* _ALLOCATORS_NO_REBIND */
class _Data_array
{ // manage array of data
public:
_Data_array(size_t)
{ // construct with _Nelts elements
}
_Data_node& operator[](int _Idx)
{ // get reference to idx element
return (_Elts[_Idx]);
}
private:
_Data_node _Elts[_Nelts];
};
#endif /* _ALLOCATORS_NO_REBIND */
class _Data_block
{ // chunk for suballocation
public:
_Data_block(size_t _Count)
: _Data(_Count)
{ // construct list
_Fl = &_Data[0];
_Free_count = _Nelts;
for (int i = 0; i < _Nelts - 1; ++i)
{ // set link and back pointer
_Data[i]._Parent = this;
_Data[i]._Next = &_Data[i + 1];
}
_Data[_Nelts - 1]._Parent = this;
_Data[_Nelts - 1]._Next = 0;
}
void *allocate()
{ // allocate from list
_Data_node *node = _Fl;
_Fl = _Fl->_Next;
--_Free_count;
return (&node->_Data);
}
static _Data_block *deallocate(void *_Ptr)
{ // deallocate to list
_Data_node *_Node =
(_Data_node*)((char*)_Ptr - offsetof(_Data_node, _Data));
_Data_block *_Block = _Node->_Parent;
_Node->_Next = _Block->_Fl;
_Block->_Fl = _Node;
++_Block->_Free_count;
return (_Block);
}
private:
_Data_array _Data;
_Data_node *_Fl;
public:
int _Free_count;
_Data_block *_Next, *_Prev;
};
_Data_block *_List;
_Data_block *_Cached_block;
};
// RUNTIME SIZE DETERMINATION
const int _WIDTH = 8;
const int _COUNT = 16;
template<class _Cache>
class rts_alloc
{ // determine cache size at runtime
public:
_DECLSPEC_ALLOCATOR void *allocate(size_t _Count)
{ // allocate _Count bytes
_Count = _ALIGN(_Count);
return ((char *)(_Count < _WIDTH * _COUNT
? caches[_IDX(_Count)].allocate(_Count)
: ::operator new(_Count)));
}
void deallocate(void *_Ptr, size_t _Count)
{ // deallocate _Count bytes
_Count = _ALIGN(_Count);
if (_Count < _WIDTH * _COUNT)
caches[_IDX(_Count)].deallocate(_Ptr, _Count);
else
::operator delete(_Ptr);
}
bool equals(const rts_alloc<_Cache>& _Other) const
{ // caches can share data
return (caches[0].equals(_Other.caches[0]));
}
private:
_Cache caches[_COUNT];
int _IDX(int _Sz)
{ // get index
return (_Sz / _WIDTH);
}
int _ALIGN(int _Sz)
{ // get alignment
return (_WIDTH * ((_Sz + _WIDTH - 1) / _WIDTH));
}
};
// ALLOCATOR BASE
template<class _Ty,
class _Sync>
class allocator_base
: public _Sync
{ // class with allocator members common to all allocators
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Ty *pointer;
typedef const _Ty *const_pointer;
typedef void *void_pointer;
typedef const void *const_void_pointer;
typedef _Ty& reference;
typedef const _Ty& const_reference;
typedef _Ty value_type;
allocator_base()
{ // default construct
}
template<class _Other>
allocator_base(const allocator_base<_Other, _Sync>& _Right)
: _Sync(_Right)
{ // construct by copying x
}
pointer address(reference _Val)
{ // get address of _Val
return (&_Val);
}
const_pointer address(const_reference _Val)
{ // get const address of _Val
return (&_Val);
}
template<class _Other>
_DECLSPEC_ALLOCATOR pointer allocate(size_type _Nx, const _Other *)
{ // allocate _Nx elements, ignore hint
return (allocate(_Nx));
}
_DECLSPEC_ALLOCATOR pointer allocate(size_type _Nx)
{ // allocate array of _Nx elements
if (_Nx <= 0)
_Nx = 0;
else if (((size_t)(-1) / sizeof (_Ty) < _Nx))
_STD _Xbad_alloc();
if (_Nx == 1)
return ((_Ty *)_Sync::allocate(sizeof (_Ty)));
else
return ((_Ty *)::operator new(_Nx * sizeof (_Ty)));
}
void deallocate(pointer _Ptr, size_type _Nx)
{ // deallocate array of _Nx elements
if (_Ptr == 0)
;
else if (_Nx == 1)
_Sync::deallocate(_Ptr, sizeof (_Ty));
else
::operator delete(_Ptr);
}
#if _ALLOCATORS_NO_REBIND
_DECLSPEC_ALLOCATOR char *_Charalloc(size_type _Count)
{ // allocate _Count bytes
return ((char *)_Sync::allocate(_Count));
}
void _Chardealloc(void *_Ptr, size_type _Count)
{ // deallocate _Count bytes
if (_Ptr != 0)
_Sync::deallocate(_Ptr, _Count);
}
#endif /* _ALLOCATORS_NO_REBIND */
template<class _Objty,
class... _Types>
void construct(_Objty *_Ptr, _Types&&... _Args)
{ // construct _Objty(_Types...) at _Ptr
::new ((void *)_Ptr) _Objty(_STD forward<_Types>(_Args)...);
}
template<class _Other>
void destroy(_Other *_Ptr)
{ // destroy *_Ptr
_Ptr->~_Other();
}
size_type max_size() const
{ // return maximum number of objects that could be allocated
return ((size_t)(-1) / sizeof (_Ty));
}
};
template<class _Ty,
class _Sync>
inline bool operator==(const allocator_base<_Ty, _Sync>& _Left,
const allocator_base<_Ty, _Sync>& _Right)
{ // compare two allocators for equality
return (_Left.equals(_Right));
}
template<class _Ty,
class _Sync>
inline bool operator!=(const allocator_base<_Ty, _Sync>& _Left,
const allocator_base<_Ty, _Sync>& _Right)
{ // compare two allocators for inequality
return (!(_Left == _Right));
}
// ALLOCATORS
#define _ALLOCATOR_VOID(name) \
template<> \
class name<void> \
{ \
public: \
name() {} \
template<class _Ty> \
name(const name<_Ty>&) {} \
template<class _Ty> \
name& operator=(const name<_Ty>&) \
{return (*this); } \
typedef void *pointer; \
typedef const void *const_pointer; \
typedef void *void_pointer; \
typedef const void *const_void_pointer; \
typedef void value_type; \
_ALLOCATOR_REBIND(name) \
}
#define _ALLOCATOR_BODY(name) \
{ \
public: \
name() {} \
template<class _Other> \
name(const name<_Other>&) {} \
template<class _Other> \
name& operator=(const name<_Other>&) \
{return (*this); } \
_ALLOCATOR_REBIND(name) \
}
#if _ALLOCATORS_NO_REBIND
#define _ALLOCATOR_REBIND(name)
#define _ALLOCATOR_DECL(cache, sync, name) \
template<class _Ty> \
class name \
: public stdext::allocators::allocator_base<_Ty, \
sync<stdext::allocators::rts_alloc<cache > > > \
_ALLOCATOR_BODY(name); \
_ALLOCATOR_VOID(name);
#else /* _ALLOCATORS_NO_REBIND */
#define _ALLOCATOR_REBIND(name) \
template<class _Other> \
struct rebind \
{ /* convert a name<_Ty> to a name<_Other> */ \
typedef name<_Other> other; \
};
#define _ALLOCATOR_DECL(cache, sync, name) \
template<class _Ty> \
class name \
: public stdext::allocators::allocator_base<_Ty, \
sync<cache > > \
_ALLOCATOR_BODY(name); \
_ALLOCATOR_VOID(name)
#endif /* _ALLOCATORS_NO_REBIND */
#define CACHE_FREELIST(max) \
stdext::allocators::cache_freelist<sizeof (_Ty), max >
#define CACHE_SUBALLOC \
stdext::allocators::cache_suballoc<sizeof (_Ty)>
#define CACHE_CHUNKLIST \
stdext::allocators::cache_chunklist<sizeof (_Ty)>
_ALLOCATOR_DECL(CACHE_FREELIST(stdext::allocators::max_none),
SYNC_DEFAULT, allocator_newdel);
_ALLOCATOR_DECL(CACHE_FREELIST(stdext::allocators::max_unbounded),
SYNC_DEFAULT, allocator_unbounded);
_ALLOCATOR_DECL(CACHE_FREELIST(stdext::allocators::max_fixed_size<10>),
SYNC_DEFAULT, allocator_fixed_size);
_ALLOCATOR_DECL(CACHE_FREELIST(stdext::allocators::max_variable_size),
SYNC_DEFAULT, allocator_variable_size);
_ALLOCATOR_DECL(CACHE_SUBALLOC,
SYNC_DEFAULT, allocator_suballoc);
_ALLOCATOR_DECL(CACHE_CHUNKLIST,
SYNC_DEFAULT, allocator_chunklist);
} // namespace allocators
} // namespace stdext
#if _HAS_ALLOCATORS_IN_STD
_STD_BEGIN
using stdext::allocators::sync_none;
using stdext::allocators::sync_per_container;
using stdext::allocators::sync_shared;
using stdext::allocators::sync_per_thread;
using stdext::allocators::max_none;
using stdext::allocators::max_unbounded;
using stdext::allocators::max_fixed_size;
using stdext::allocators::max_variable_size;
using stdext::allocators::freelist;
using stdext::allocators::cache_freelist;
using stdext::allocators::cache_suballoc;
using stdext::allocators::cache_chunklist;
using stdext::allocators::rts_alloc;
using stdext::allocators::allocator_base;
_STD_END
#endif /* _HAS_ALLOCATORS_IN_STD */
#pragma pop_macro("new")
#pragma warning(pop)
#pragma pack(pop)
#endif /* RC_INVOKED */
#endif /* _ALLOCATORS_ */
/*
* Copyright (c) by P.J. Plauger. All rights reserved.
* Consult your license regarding permissions and restrictions.
V6.50:0009 */