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.

91 lines
1.7 KiB

  1. /*++
  2. Copyright (C) 1999-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. #include "precomp.h"
  8. #include <arena.h>
  9. #include <align.h>
  10. class CGetHeap
  11. {
  12. private:
  13. HANDLE m_hHeap;
  14. BOOL m_bNewHeap;
  15. public:
  16. CGetHeap();
  17. ~CGetHeap();
  18. operator HANDLE(){ return m_hHeap; };
  19. };
  20. CGetHeap g_Heap;
  21. CGetHeap::CGetHeap():m_bNewHeap(FALSE)
  22. {
  23. #ifdef DBG
  24. DWORD dwUsePrivateHeap = 1;
  25. #else
  26. DWORD dwUsePrivateHeap = 0;
  27. #endif
  28. HKEY hKey;
  29. LONG lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  30. __TEXT("Software\\Microsoft\\WBEM\\CIMOM"),
  31. NULL,
  32. KEY_READ,
  33. &hKey);
  34. if (ERROR_SUCCESS == lRet)
  35. {
  36. DWORD dwType;
  37. DWORD dwSize = sizeof(DWORD);
  38. lRet = RegQueryValueEx(hKey,
  39. __TEXT("EnablePrivateMofdHeap"),
  40. NULL,
  41. &dwType,
  42. (BYTE *)&dwUsePrivateHeap,
  43. &dwSize);
  44. RegCloseKey(hKey);
  45. }
  46. if (dwUsePrivateHeap)
  47. {
  48. m_hHeap = HeapCreate(0,0,0);
  49. if (m_hHeap)
  50. m_bNewHeap = TRUE;
  51. }
  52. else
  53. {
  54. m_hHeap = CWin32DefaultArena::GetArenaHeap();
  55. }
  56. if (NULL == m_hHeap)
  57. m_hHeap = GetProcessHeap();
  58. };
  59. CGetHeap::~CGetHeap()
  60. {
  61. if (m_bNewHeap)
  62. {
  63. HeapDestroy(m_hHeap);
  64. }
  65. };
  66. void* __cdecl operator new ( size_t size )
  67. {
  68. void * p = HeapAlloc(g_Heap,0,size);
  69. return p;
  70. }
  71. void __cdecl operator delete ( void* pv )
  72. {
  73. HeapFree(g_Heap,0,pv);
  74. }