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
2.1 KiB

  1. // --------------------------------------------------------------------------------
  2. // Memutil.cpp
  3. // This file is linked into other projects.
  4. // --------------------------------------------------------------------------------
  5. #include "pch.hxx"
  6. // --------------------------------------------------------------------------------
  7. // ZeroAllocate
  8. // --------------------------------------------------------------------------------
  9. LPVOID ZeroAllocate(DWORD cbSize)
  10. {
  11. LPVOID pv = g_pMalloc->Alloc(cbSize);
  12. if (pv)
  13. ZeroMemory(pv, cbSize);
  14. return pv;
  15. }
  16. // --------------------------------------------------------------------------------
  17. // MemAlloc
  18. // --------------------------------------------------------------------------------
  19. BOOL MemAlloc(LPVOID* ppv, ULONG cb)
  20. {
  21. Assert(ppv && cb);
  22. *ppv = g_pMalloc->Alloc(cb);
  23. if (NULL == *ppv)
  24. return FALSE;
  25. return TRUE;
  26. }
  27. // --------------------------------------------------------------------------------
  28. // HrAlloc
  29. // --------------------------------------------------------------------------------
  30. HRESULT HrAlloc(LPVOID *ppv, ULONG cb)
  31. {
  32. Assert(ppv && cb);
  33. *ppv = g_pMalloc->Alloc(cb);
  34. if (NULL == *ppv)
  35. return TrapError(E_OUTOFMEMORY);
  36. return S_OK;
  37. }
  38. // --------------------------------------------------------------------------------
  39. // MemRealloc
  40. // --------------------------------------------------------------------------------
  41. BOOL MemRealloc(LPVOID *ppv, ULONG cbNew)
  42. {
  43. Assert(ppv && cbNew);
  44. LPVOID pv = g_pMalloc->Realloc(*ppv, cbNew);
  45. if (NULL == pv)
  46. return FALSE;
  47. *ppv = pv;
  48. return TRUE;
  49. }
  50. // --------------------------------------------------------------------------------
  51. // HrRealloc
  52. // --------------------------------------------------------------------------------
  53. HRESULT HrRealloc(LPVOID *ppv, ULONG cbNew)
  54. {
  55. Assert(ppv);
  56. LPVOID pv = g_pMalloc->Realloc(*ppv, cbNew);
  57. if (NULL == pv && 0 != cbNew)
  58. return TrapError(E_OUTOFMEMORY);
  59. *ppv = pv;
  60. return S_OK;
  61. }
  62. // "new" and "delete" come from libcmt.lib