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.

68 lines
1.1 KiB

  1. /*
  2. * Global memory allocation
  3. */
  4. #ifndef DUI_BASE_ALLOC_H_INCLUDED
  5. #define DUI_BASE_ALLOC_H_INCLUDED
  6. #pragma once
  7. #include <new.h>
  8. namespace DirectUI
  9. {
  10. extern HANDLE g_hHeap;
  11. inline void* HAlloc(SIZE_T s)
  12. {
  13. return HeapAlloc(g_hHeap, 0, s);
  14. }
  15. inline void* HAllocAndZero(SIZE_T s)
  16. {
  17. return HeapAlloc(g_hHeap, HEAP_ZERO_MEMORY, s);
  18. }
  19. inline void* HReAlloc(void* p, SIZE_T s)
  20. {
  21. return HeapReAlloc(g_hHeap, 0, p, s);
  22. }
  23. inline void* HReAllocAndZero(void* p, SIZE_T s)
  24. {
  25. return HeapReAlloc(g_hHeap, HEAP_ZERO_MEMORY, p, s);
  26. }
  27. inline void HFree(void* p)
  28. {
  29. HeapFree(g_hHeap, 0, p);
  30. }
  31. template <typename T> inline T* HNew()
  32. {
  33. T* p = (T*)HAlloc(sizeof(T));
  34. if (p)
  35. new(p) T;
  36. return p;
  37. }
  38. template <typename T> inline T* HNewAndZero()
  39. {
  40. T* p = (T*)HAllocAndZero(sizeof(T));
  41. if (p)
  42. new(p) T;
  43. return p;
  44. }
  45. template <typename T> inline void HDelete(T* p)
  46. {
  47. p->~T();
  48. HFree(p);
  49. }
  50. } // namespace DirectUI
  51. #endif // DUI_BASE_ALLOC_H_INCLUDED