Leaked source code of windows server 2003
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.

74 lines
2.2 KiB

  1. /*
  2. * M E M . H
  3. *
  4. * DAV basic memory allocators. Implementation of this class is
  5. * owned by the individual implementations
  6. *
  7. * Copyright 1986-1997 Microsoft Corporation, All Rights Reserved
  8. */
  9. #ifndef _MEM_H_
  10. #define _MEM_H_
  11. #ifdef _DAVCDATA_
  12. #error "mem.h defines throwing allocators"
  13. #endif
  14. // Global heap "class" ---------------------------------------------------------
  15. //
  16. // This really only acts as a namespace. I.e. there are no non-static members.
  17. // For historical reasons (and, mainly, to avoid changing a LOT of code from
  18. // calling "g_heap.Fn()" to calling "g_heap::Fn()"), g_heap still appears
  19. // outwardly to be a real object.
  20. //
  21. // !!! CHeap is used by multiple components. Specifically, it may be
  22. // *IMPLEMENTED* by multiple components in various locations.
  23. // When changing the CHeap interface, make sure to recompile
  24. // EVERYTHING in the project.
  25. //
  26. struct CHeap
  27. {
  28. static BOOL FInit();
  29. static void Deinit();
  30. static LPVOID Alloc( SIZE_T cb );
  31. static LPVOID Realloc( LPVOID lpv, SIZE_T cb );
  32. static VOID Free( LPVOID pv );
  33. };
  34. extern CHeap g_heap;
  35. // Safe allocators
  36. //
  37. #include <ex\exmem.h>
  38. // Try using pragmas to turn off the undesired warnings from the STL.
  39. #pragma warning(disable:4663) // C language, template<> syntax
  40. #pragma warning(disable:4244) // return conversion, data loss
  41. #include <memory>
  42. // And undo it all so that we still get good checking!
  43. #pragma warning(default:4663) // C language, template<> syntax
  44. #pragma warning(default:4244) // return conversion, data loss
  45. // ========================================================================
  46. //
  47. // TEMPLATE CLASS heap_allocator<>
  48. //
  49. // Allocator class to work with the STL (Standard C++ Template Library).
  50. // Allocations actually handled by our global heap allocator.
  51. //
  52. template<class _Ty>
  53. class heap_allocator : public std::allocator<_Ty>
  54. {
  55. public:
  56. pointer allocate(size_type _N, const void *)
  57. {return (pointer) _Charalloc(_N * sizeof(_Ty)); }
  58. char _FARQ *_Charalloc(size_type _N)
  59. {return (char _FARQ *) g_heap.Alloc(_N); }
  60. void deallocate(void _FARQ *_P, size_type)
  61. {g_heap.Free(_P); }
  62. };
  63. #endif // _MEM_H_