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.

58 lines
1.4 KiB

  1. // alloc.h
  2. //
  3. // Allocator that uses the process heap. new/delete gets confused across
  4. // the dll boundary
  5. //
  6. #pragma once
  7. #ifndef __ALLOC_H
  8. #define __ALLOC_H
  9. // TEMPLATE FUNCTION _Allocate
  10. template<class _Ty> inline
  11. _Ty _FARQ *_Heap_Allocate(_PDFT _N, _Ty _FARQ *)
  12. {if (_N < 0)
  13. _N = 0;
  14. return ((_Ty _FARQ *)HeapAlloc(GetProcessHeap(), 0,
  15. (_SIZT)_N * sizeof (_Ty))); }
  16. // TEMPLATE CLASS allocator
  17. template<class _Ty>
  18. class heap_allocator {
  19. public:
  20. typedef _SIZT size_type;
  21. typedef _PDFT difference_type;
  22. typedef _Ty _FARQ *pointer;
  23. typedef const _Ty _FARQ *const_pointer;
  24. typedef _Ty _FARQ& reference;
  25. typedef const _Ty _FARQ& const_reference;
  26. typedef _Ty value_type;
  27. pointer address(reference _X) const
  28. {return (&_X); }
  29. const_pointer address(const_reference _X) const
  30. {return (&_X); }
  31. pointer allocate(size_type _N, const void *)
  32. {return (_Heap_Allocate((difference_type)_N, (pointer)0)); }
  33. char _FARQ *_Charalloc(size_type _N)
  34. {return (_Heap_Allocate((difference_type)_N,
  35. (char _FARQ *)0)); }
  36. void deallocate(void _FARQ *_P, size_type)
  37. { HeapFree(GetProcessHeap(), 0, _P); }
  38. void construct(pointer _P, const _Ty& _V)
  39. {_Construct(_P, _V); }
  40. void destroy(pointer _P)
  41. {_Destroy(_P); }
  42. _SIZT max_size() const
  43. {_SIZT _N = (_SIZT)(-1) / sizeof (_Ty);
  44. return (0 < _N ? _N : 1); }
  45. bool operator== (const heap_allocator& rhs)
  46. { return true; }
  47. };
  48. #endif // __ALLOC_H