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.

207 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1992-1997 Microsoft Corporation
  3. Module Name:
  4. mem.c
  5. Abstract:
  6. Routines for memory allocation and deallocation.
  7. Environment:
  8. User Mode - Win32
  9. --*/
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // //
  12. // Include files //
  13. // //
  14. ///////////////////////////////////////////////////////////////////////////////
  15. #include "globals.h"
  16. ///////////////////////////////////////////////////////////////////////////////
  17. // //
  18. // Global variables //
  19. // //
  20. ///////////////////////////////////////////////////////////////////////////////
  21. HANDLE g_HeapHandle;
  22. ///////////////////////////////////////////////////////////////////////////////
  23. // //
  24. // Public procudures //
  25. // //
  26. ///////////////////////////////////////////////////////////////////////////////
  27. BOOL
  28. H323HeapCreate(
  29. )
  30. /*++
  31. Routine Description:
  32. Creates private heap for service provider's private structures.
  33. Arguments:
  34. None.
  35. Return Values:
  36. Returns true if successful.
  37. --*/
  38. {
  39. // create master agent heap
  40. g_HeapHandle = HeapCreate(
  41. H323_HEAP_FLAGS,
  42. H323_HEAP_INITIAL_SIZE,
  43. H323_HEAP_MAXIMUM_SIZE
  44. );
  45. // validate heap handle
  46. if (g_HeapHandle == NULL) {
  47. H323DBG((
  48. DEBUG_LEVEL_ERROR,
  49. "error %d creating private heap.\n",
  50. GetLastError()
  51. ));
  52. }
  53. // return success if created
  54. return (g_HeapHandle != NULL);
  55. }
  56. BOOL
  57. H323HeapDestroy(
  58. )
  59. /*++
  60. Routine Description:
  61. Destroys private heap for service provider's private structures.
  62. Arguments:
  63. None.
  64. Return Values:
  65. Returns true if successful.
  66. --*/
  67. {
  68. // validate handle
  69. if (g_HeapHandle != NULL) {
  70. // release heap handle
  71. HeapDestroy(g_HeapHandle);
  72. // re-initialize
  73. g_HeapHandle = NULL;
  74. }
  75. return TRUE;
  76. }
  77. LPVOID
  78. H323HeapAlloc(
  79. UINT nBytes
  80. )
  81. /*++
  82. Routine Description:
  83. Allocates memory from service provider's private heap.
  84. Arguments:
  85. nBytes - number of bytes to allocate.
  86. Return Values:
  87. Returns true if successful.
  88. --*/
  89. {
  90. // allocate memory from private heap (and initialize)
  91. return HeapAlloc(g_HeapHandle, HEAP_ZERO_MEMORY, nBytes);
  92. }
  93. LPVOID
  94. H323HeapReAlloc(
  95. LPVOID pMem,
  96. UINT nBytes
  97. )
  98. /*++
  99. Routine Description:
  100. Reallocates memory from service provider's private heap.
  101. Arguments:
  102. pMem - pointer to memory block to reallocate.
  103. nBytes - number of bytes to allocate.
  104. Return Values:
  105. Returns true if successful.
  106. --*/
  107. {
  108. // reallocate memory from private heap (and initialize)
  109. return HeapReAlloc(g_HeapHandle, HEAP_ZERO_MEMORY, pMem, nBytes);
  110. }
  111. VOID
  112. H323HeapFree(
  113. LPVOID pMem
  114. )
  115. /*++
  116. Routine Description:
  117. Frees memory from service provider's private heap.
  118. Arguments:
  119. pMem - pointer to memory block to release.
  120. Return Values:
  121. Returns true if successful.
  122. --*/
  123. {
  124. // validate pointer
  125. if (pMem != NULL) {
  126. // release agent memory
  127. HeapFree(g_HeapHandle, 0, pMem);
  128. }
  129. }