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.

68 lines
2.1 KiB

  1. #ifndef _INC_MEM
  2. #define _INC_MEM
  3. // wrappers for private allocations, near in 16 bits
  4. #define NearAlloc(cb) ((void NEAR*)LocalAlloc(LPTR, (cb)))
  5. #define NearReAlloc(pb, cb) ((void NEAR*)LocalReAlloc((HLOCAL)(pb), (cb), LMEM_MOVEABLE | LMEM_ZEROINIT))
  6. #define NearFree(pb) (LocalFree((HLOCAL)(pb)) ? FALSE : TRUE)
  7. #define NearSize(pb) LocalSize(pb)
  8. #ifdef WIN32
  9. //
  10. // These macros are used in our controls, that in 32 bits we simply call
  11. // LocalAlloc as to have the memory associated with the process that created
  12. // it and as such will be cleaned up if the process goes away.
  13. //
  14. #ifdef DEBUG
  15. LPVOID WINAPI ControlAlloc(HANDLE hheap, DWORD cb);
  16. LPVOID WINAPI ControlReAlloc(HANDLE hheap, LPVOID pb, DWORD cb);
  17. BOOL WINAPI ControlFree(HANDLE hheap, LPVOID pb);
  18. SIZE_T WINAPI ControlSize(HANDLE hheap, LPVOID pb);
  19. #else // DEBUG
  20. #define ControlAlloc(hheap, cb) HeapAlloc((hheap), HEAP_ZERO_MEMORY, (cb))
  21. #define ControlReAlloc(hheap, pb, cb) HeapReAlloc((hheap), HEAP_ZERO_MEMORY, (pb),(cb))
  22. #define ControlFree(hheap, pb) HeapFree((hheap), 0, (pb))
  23. #define ControlSize(hheap, pb) HeapSize((hheap), 0, (LPCVOID)(pb))
  24. #endif // DEBUG
  25. BOOL Str_Set(LPTSTR *ppsz, LPCTSTR psz); // in the process heap
  26. #else // WIN32
  27. //
  28. // In 16 bit code we need the Allocs to go from our heap code as we do not
  29. // want to limit them to 64K of data. If we have some type of notification of
  30. // 16 bit application termination, We may want to see if we can
  31. // dedicate different heaps for different processes to cleanup...
  32. //
  33. #define ControlAlloc(hheap, cb) Alloc(cb) /* calls to verify heap exists */
  34. #define ControlReAlloc(hheap, pb, cb) ReAlloc(pb, cb)
  35. #define ControlFree(hheap, pb) Free(pb)
  36. #define ControlSize(hheap, pb) GetSize((LPCVOID)pb)
  37. #define Str_Set(p, s) Str_SetPtr(p, s) // use shared heap for win16
  38. #endif // WIN32
  39. #ifndef WINNT
  40. extern HANDLE g_hSharedHeap;
  41. HANDLE InitSharedHeap(void);
  42. __inline HANDLE
  43. GetSharedHeapHandle(void)
  44. {
  45. if (g_hSharedHeap)
  46. {
  47. return g_hSharedHeap;
  48. }
  49. else
  50. {
  51. return InitSharedHeap();
  52. }
  53. }
  54. #endif
  55. #endif // !_INC_MEM