Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.5 KiB

  1. #ifndef __PPT_ALLOCATOR_
  2. #define __PPT_ALLOCATOR_
  3. #include <memory>
  4. /**************************************************************************
  5. * Template name: heap_allocator
  6. *
  7. * Purpose: Allocator class to handle STL allocations
  8. *
  9. */
  10. template<class _Ty>
  11. class PtHeap_allocator : public std::allocator<_Ty>
  12. {
  13. public:
  14. PtHeap_allocator()
  15. {
  16. __hHeap = GetProcessHeap();
  17. };
  18. pointer allocate(size_type _N, const void *)
  19. {return (pointer) _Charalloc(_N * sizeof(_Ty)); }
  20. char* _Charalloc(size_type _N)
  21. {return (char*) HeapAlloc(__hHeap, 0, _N); }
  22. void deallocate(void* _P, size_type)
  23. {HeapFree(__hHeap, 0, _P); }
  24. private:
  25. HANDLE __hHeap;
  26. };
  27. // Defines strings that use the above allocator to that the DMI heap stuff is used.
  28. #include <string>
  29. #include <queue>
  30. typedef std::basic_string<CHAR, std::char_traits<CHAR>, PtHeap_allocator<CHAR> > PtStlString;
  31. typedef std::basic_string<WCHAR, std::char_traits<WCHAR>, PtHeap_allocator<WCHAR> > PtStlWstring;
  32. #if 0// uses new allocator
  33. template<class Key, class T, class Pred = less<Key> >
  34. class PtStlMap : public std::map<Key, T, Pred, PtHeap_allocator<T> >{};
  35. template<class T>
  36. class PtStlQueue : public std::queue<T, deque<T, PtHeap_allocator<T> > > {};
  37. #else
  38. template<class Key, class T, class Pred = less<Key> >
  39. class PtStlMap : public std::map<Key, T, Pred, std::allocator<T> >{};
  40. template<class T>
  41. class PtStlQueue : public std::queue<T, deque<T, std::allocator<T> > > {};
  42. #endif
  43. #endif // __PPT_ALLOCATOR_