3 #include <cds/memory/michael/allocator.h>
7 namespace ma = cds::memory::michael;
10 ma::opt::procheap_stat<ma::procheap_empty_stat>,
11 ma::opt::os_allocated_stat<ma::os_allocated_empty>,
12 ma::opt::check_bounds<ma::debug_bound_checking>
13 > t_MichaelHeap_NoStat;
16 ma::opt::procheap_stat<ma::procheap_atomic_stat >,
17 ma::opt::os_allocated_stat<ma::os_allocated_atomic >,
18 ma::opt::check_bounds<ma::debug_bound_checking>
21 typedef ma::summary_stat summary_stat;
23 extern t_MichaelHeap_NoStat s_MichaelHeap_NoStat;
24 extern t_MichaelHeap_Stat s_MichaelHeap_Stat;
27 class MichaelHeap_NoStat
38 pointer allocate( size_t nSize, const void * pHint )
40 return reinterpret_cast<pointer>( s_MichaelHeap_NoStat.alloc( sizeof(T) * nSize ) );
43 void deallocate( pointer p, size_t nCount )
45 s_MichaelHeap_NoStat.free( p );
48 static void stat(summary_stat& s)
50 s_MichaelHeap_NoStat.summaryStat(s);
55 class std_allocator: public std::allocator<T>
62 static void stat(summary_stat& s)
67 class MichaelHeap_Stat
77 pointer allocate( size_t nSize, const void * pHint )
79 return reinterpret_cast<pointer>( s_MichaelHeap_Stat.alloc( sizeof(T) * nSize ) );
82 void deallocate( pointer p, size_t nCount )
84 s_MichaelHeap_Stat.free( p );
87 static void stat(summary_stat& s)
89 s_MichaelHeap_Stat.summaryStat(s);
93 template <typename T, size_t ALIGN>
94 class MichaelAlignHeap_NoStat
104 pointer allocate( size_t nSize, const void * pHint )
106 return reinterpret_cast<pointer>( s_MichaelHeap_NoStat.alloc_aligned( sizeof(T) * nSize, ALIGN ) );
109 void deallocate( pointer p, size_t nCount )
111 s_MichaelHeap_NoStat.free_aligned( p );
114 static void stat(summary_stat& s)
116 s_MichaelHeap_NoStat.summaryStat(s);
120 template <typename T, size_t ALIGN>
121 class MichaelAlignHeap_Stat {
123 typedef T value_type;
130 pointer allocate( size_t nSize, const void * pHint )
132 return reinterpret_cast<pointer>( s_MichaelHeap_Stat.alloc_aligned( sizeof(T) * nSize, ALIGN ) );
135 void deallocate( pointer p, size_t nCount )
137 s_MichaelHeap_Stat.free_aligned( p );
140 static void stat(summary_stat& s)
142 s_MichaelHeap_Stat.summaryStat(s);
146 template <typename T, size_t ALIGN>
147 class system_aligned_allocator
150 typedef T value_type;
157 pointer allocate( size_t nSize, const void * pHint )
159 return reinterpret_cast<pointer>( cds::OS::aligned_malloc( sizeof(T) * nSize, ALIGN ) );
162 void deallocate( pointer p, size_t nCount )
164 cds::OS::aligned_free( p );
167 static void stat(summary_stat& s)
171 static inline std::ostream& operator <<(std::ostream& os, const summary_stat& s)
173 os << "\t alloc from active: " << s.nAllocFromActive << "\n"
174 << "\t alloc from partial: " << s.nAllocFromPartial << "\n"
175 << "\t alloc from new: " << s.nAllocFromNew << "\n"
176 << "\t free call count: " << s.nFreeCount << "\n"
177 << "\t superblock allocated: " << s.nPageAllocCount << "\n"
178 << "\t superblock deallocated: " << s.nPageDeallocCount << "\n"
179 << "\t superblock desc allocated: " << s.nDescAllocCount << "\n"
180 << "\t superblock full desc: " << s.nDescFull << "\n"
181 << "\t total allocated bytes: " << s.nBytesAllocated << "\n"
182 << "\t total deallocated bytes: " << s.nBytesDeallocated << "\n"
183 << "\tOS-allocated large blocks\n"
184 << "\t alloc call count: " << s.nSysAllocCount << "\n"
185 << "\t free call count: " << s.nSysFreeCount << "\n"
186 << "\t total allocated bytes: " << s.nSysBytesAllocated << "\n"
187 << "\t total deallocated bytes: " << s.nSysBytesDeallocated << "\n"
188 << "\tCAS contention indicators\n"
189 << "\t updating active field of active block: " << s.nActiveDescCASFailureCount << "\n"
190 << "\t updating anchor field of active block: " << s.nActiveAnchorCASFailureCount << "\n"
191 << "\tupdating active field of partial block: " << s.nPartialDescCASFailureCount << "\n"
192 << "\tupdating anchor field of partial block: " << s.nPartialAnchorCASFailureCount