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.

217 lines
6.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: MemAPI.HXX
  7. //
  8. // Contents: Internal memory allocation routines
  9. //
  10. // Classes: CPrivAlloc
  11. //
  12. // Functions: PrivMemAlloc
  13. // PrivMemAlloc8
  14. // PrivMemFree
  15. // UtGlobalxxx
  16. //
  17. // History:
  18. // 25-Jan-94 alexgo added PubMemReAlloc
  19. // 04-Nov-93 AlexT Created
  20. //
  21. // Notes:
  22. //
  23. // For memory that the application can free with the task IMalloc, use
  24. // CoTaskMemAlloc and CoTaskMemFree.
  25. //
  26. // For process local memory that is used internally, use PrivMemAlloc and
  27. // PrivMemFree.
  28. //
  29. // For process local class instances, use CPrivAlloc as a base class.
  30. //
  31. // PubMemAlloc, PubMemRealloc, and PubMemFree are obsolete.
  32. //--------------------------------------------------------------------------
  33. #ifndef __MEMAPI_HXX__
  34. #define __MEMAPI_HXX__
  35. //PubMemAlloc is obsolete. Use CoTaskMemAlloc.
  36. #define PubMemAlloc(ulcb) CoTaskMemAlloc(ulcb)
  37. //PubMemRealloc is obsolete. Use CoTaskMemRealloc.
  38. #define PubMemRealloc(pv, ulcb) CoTaskMemRealloc(pv, ulcb)
  39. //PubMemFree is obsolete. Use CoTaskMemFree.
  40. #define PubMemFree(pv) CoTaskMemFree(pv)
  41. //+-------------------------------------------------------------------------
  42. //
  43. // Function: PrivMemAlloc
  44. //
  45. // Synopsis: Allocate private memory block
  46. //
  47. // Arguments: [ulcb] -- size of memory block
  48. //
  49. // Returns: Pointer to memory block
  50. //
  51. //--------------------------------------------------------------------------
  52. extern HANDLE g_hHeap;
  53. typedef
  54. LPVOID (WINAPI HEAP_ALLOC_ROUTINE)(
  55. HANDLE hHeap,
  56. DWORD dwFlags,
  57. SIZE_T dwBytes);
  58. extern HEAP_ALLOC_ROUTINE * pfnHeapAlloc;
  59. // We might want to make this conditional on debug builds in ole32, but
  60. // right now PrivMemAlloc goes straight to the heap because it's used in
  61. // RPCSS.
  62. //#define PrivMemAlloc(ulcb) CoTaskMemAlloc(ulcb)
  63. #define PrivMemAlloc(ulcb) (*pfnHeapAlloc)(g_hHeap, 0, (ulcb))
  64. //+-------------------------------------------------------------------------
  65. //
  66. // Function: PrivMemAlloc8
  67. //
  68. // Synopsis: Allocate private memory block aligned on 8 byte boundary
  69. //
  70. // Arguments: [ulcb] -- size of memory block
  71. //
  72. // Returns: Pointer to memory block
  73. //
  74. // History: 14 Jul 94 AlexMit Created
  75. //
  76. // Notes: The allocator already aligns on 8byte boundary, but this method
  77. // remains to document the code that depends on this alignment.
  78. //
  79. //--------------------------------------------------------------------------
  80. #define PrivMemAlloc8(ulcb) PrivMemAlloc(((ulcb)+7)&~7)
  81. //+-------------------------------------------------------------------------
  82. //
  83. // Function: PrivMemFree
  84. //
  85. // Synopsis: Frees private memory block
  86. //
  87. // Arguments: [pv] -- pointer to memory block
  88. //
  89. //--------------------------------------------------------------------------
  90. typedef
  91. BOOL (WINAPI HEAP_FREE_ROUTINE)(
  92. HANDLE hHeap,
  93. DWORD dwFlags,
  94. LPVOID lpMem);
  95. extern HEAP_FREE_ROUTINE *pfnHeapFree;
  96. //#define PrivMemFree(pv) CoTaskMemFree(pv)
  97. #define PrivMemFree(pv) (*pfnHeapFree)(g_hHeap, 0, (pv))
  98. //+-------------------------------------------------------------------------
  99. //
  100. // Function: PrivMemFree8
  101. //
  102. // Synopsis: Free private memory block aligned on 8 byte boundary
  103. //
  104. // Arguments: [pv] -- pointer to memory block
  105. //
  106. // Returns: none
  107. //
  108. // History: 23 May 95 MurthyS Created
  109. //
  110. // Notes:
  111. //
  112. //--------------------------------------------------------------------------
  113. #define PrivMemFree8 PrivMemFree
  114. //+-------------------------------------------------------------------------
  115. //
  116. // Class: CPrivAlloc
  117. //
  118. // Purpose: Base class for process local classes
  119. //
  120. // Interface: operator new
  121. // operator delete
  122. //
  123. // History: 04-Nov-93 AlexT Created
  124. //
  125. //--------------------------------------------------------------------------
  126. class CPrivAlloc
  127. {
  128. public:
  129. void *operator new(size_t size)
  130. {
  131. return PrivMemAlloc(size);
  132. };
  133. void operator delete(void *pv)
  134. {
  135. PrivMemFree(pv);
  136. };
  137. };
  138. void FAR* __cdecl operator new(size_t size);
  139. void __cdecl operator delete(void FAR* ptr);
  140. //+-------------------------------------------------------------------------
  141. //
  142. // Function: UtGlobalxxx
  143. //
  144. // Synopsis: Debugging version of global memory functions
  145. //
  146. // History: 28-Feb-94 AlexT Created
  147. // 10-May-94 KevinRo Disabled for DDE build
  148. //
  149. // Notes:
  150. //
  151. // DDE uses GlobalAlloc for exchanging data between 16 and 32 bit
  152. // servers, as well as for passing data across to other processes.
  153. // The routine GlobalSize() is used quite often in these routines to
  154. // determine the amount of data in the block. Therefore, we shouldn't go
  155. // adding extra data to the block, like these routines do. Therefore,
  156. // we won't override these routines if OLE_DDE_NO_GLOBAL_TRACKING is defined
  157. //
  158. //
  159. //--------------------------------------------------------------------------
  160. #if DBG==1 && defined(WIN32) && !defined(OLE_DDE_NO_GLOBAL_TRACKING)
  161. #define GlobalAlloc(uiFlag, cbBytes) UtGlobalAlloc(uiFlag, cbBytes)
  162. #define GlobalReAlloc(h, cb, uiFlag) UtGlobalReAlloc(h, cb, uiFlag)
  163. #define GlobalLock(h) UtGlobalLock(h)
  164. #define GlobalUnlock(h) UtGlobalUnlock(h)
  165. #define GlobalFree(h) UtGlobalFree(h)
  166. #define SetClipboardData(uFormat, hMem) UtSetClipboardData(uFormat, hMem)
  167. extern "C" HGLOBAL WINAPI UtGlobalAlloc(UINT uiFlag, SIZE_T cbUser);
  168. extern "C" HGLOBAL WINAPI UtGlobalReAlloc(HGLOBAL hGlobal, SIZE_T cbUser, UINT uiFlag);
  169. extern "C" LPVOID WINAPI UtGlobalLock(HGLOBAL hGlobal);
  170. extern "C" BOOL WINAPI UtGlobalUnlock(HGLOBAL hGlobal);
  171. extern "C" HGLOBAL WINAPI UtGlobalFree(HGLOBAL hGlobal);
  172. extern "C" HANDLE WINAPI UtSetClipboardData(UINT uFormat, HANDLE hMem);
  173. extern "C" void UtGlobalFlushTracking(void);
  174. #else
  175. #define UtGlobalFlushTracking() NULL
  176. #define UtGlobalStopTracking(hGlobal) NULL
  177. #endif // !(DBG==1 && defined(WIN32))
  178. #endif // !defined(__MEMAPI_HXX__)