#include #include "debug.h" template class winheap_allocator { public: typedef T value_type; typedef value_type* pointer; typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; typedef size_t size_type; typedef ptrdiff_t difference_type; template struct rebind { typedef winheap_allocator other; }; winheap_allocator(HANDLE heap) { this->heap = heap; } // winheap_allocator(const winheap_allocator& a) // { // heap = a.heap; // } template winheap_allocator(const winheap_allocator& a) { heap = a.heap; } ~winheap_allocator() { } pointer address(reference x) const { return &x; } const_pointer address(const_reference x) const { return x; } pointer allocate(size_type n, const_pointer = 0) { void* p = HeapAlloc(heap, 0, n * sizeof(T)); // if (!p) // throw std::bad_alloc(); return static_cast(p); } char* _Charalloc(size_type n) { return rebind::other(*this).allocate(n, (char*) 0); } void deallocate(void* p, size_type) { BOOL ret = HeapFree(heap, 0, p); DBGASSERT(ret == TRUE); } size_type max_size() const { return static_cast(-1) / sizeof(T); } void construct(pointer p, const value_type& x) { new (p) value_type(x); } void destroy(pointer p) { p->~value_type(); } HANDLE heap; private: void operator=(const winheap_allocator&); }; template<> class winheap_allocator { typedef void value_type; typedef void* pointer; typedef const void* const_pointer; template struct rebind { typedef winheap_allocator other; }; }; template inline bool operator==(const winheap_allocator& a, const winheap_allocator& b) { return a.heap == b.heap; } template inline bool operator!=(const winheap_allocator& a, const winheap_allocator& b) { return a.heap != b.heap; }