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.

156 lines
4.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: DfMem.HXX
  7. //
  8. // Contents: Memory headers
  9. //
  10. // Functions: DfCreateSharedAllocator
  11. // new (DBG only)
  12. // delete (DBG only)
  13. //
  14. // Classes: CMallocBased
  15. // CLocalAlloc
  16. //
  17. // History: 18-May-93 AlexT Created
  18. //
  19. //--------------------------------------------------------------------------
  20. #ifndef __DFMEM_HXX__
  21. #define __DFMEM_HXX__
  22. #ifndef _HEAP_MAXREQ
  23. # define _HEAP_MAXREQ 0xffffffff // from 16-bit malloc.h
  24. #endif
  25. #if defined(WIN32)
  26. #define TaskMemAlloc CoTaskMemAlloc
  27. #define TaskMemFree CoTaskMemFree
  28. // Creating the shared memory indirects through a pointer for most
  29. // efficient once-per-process initialisation
  30. extern HRESULT DfCreateSharedAllocator (IMalloc **ppm, BOOL fTaskMemory);
  31. // Constants related to the Docfile shared memory
  32. #define DOCFILE_SM_NAME L"XXYZZY1OleSharedHeap"
  33. #ifdef MULTIHEAP
  34. #ifdef _WIN64
  35. #define DOCFILE_SM_SIZE 0x1000000L /* 16 Meg */
  36. #define DOCFILE_SM_LIMIT 0x80000000L /* 2 Gig */
  37. #else
  38. #define DOCFILE_SM_SIZE 0x400000L /* 4 Meg */
  39. #define DOCFILE_SM_LIMIT 0x40000000L /* 1 Gig */
  40. #endif // _WIN64
  41. #else
  42. #define DOCFILE_SM_SIZE 0x4000000L
  43. #endif
  44. #define DOCFILE_SM_NAMELEN 32
  45. #else // 16 bit
  46. // Use TaskMemAlloc and TaskMemFree for allocations that may be returned
  47. extern void *TaskMemAlloc(ULONG ulcb);
  48. extern void TaskMemFree(void *pv);
  49. # if DBG==0
  50. # define DfCreateSharedAllocator(ppm, fTaskmemory) \
  51. CoCreateStandardMalloc(MEMCTX_SHARED, ppm)
  52. # else
  53. extern HRESULT DfCreateSharedAllocator(IMalloc **ppm, BOOL fTaskMemory);
  54. # endif
  55. #endif // defined(WIN32)
  56. class CMallocBased
  57. {
  58. public:
  59. void *operator new(size_t size, IMalloc * const pMalloc);
  60. void operator delete(void *pv);
  61. // deallocate the memory without Mutex
  62. // (requires that the MUtex is already locked)
  63. void deleteNoMutex(void *pv);
  64. };
  65. //+-------------------------------------------------------------------------
  66. //
  67. // Class: CLocalAlloc
  68. //
  69. // Purpose: Base class for classes allocated in task local memory.
  70. //
  71. // Interface: See below.
  72. //
  73. // History: 17-Aug-92 PhilipLa Created.
  74. //
  75. //--------------------------------------------------------------------------
  76. class CLocalAlloc
  77. {
  78. public:
  79. #if DBG==0 || defined(MULTIHEAP)
  80. inline
  81. #endif
  82. void *operator new(size_t size);
  83. #if DBG==0 || defined(MULTIHEAP)
  84. inline
  85. #endif
  86. void operator delete(void *pv);
  87. };
  88. #if DBG==0 || defined(MULTIHEAP)
  89. //+-------------------------------------------------------------------------
  90. //
  91. // Method: CLocalAlloc::operator new, public
  92. //
  93. // Synopsis: Overloaded new operator to allocate objects from
  94. // task local space.
  95. //
  96. // Arguments: [size] -- Size of block to allocate
  97. //
  98. // Returns: Pointer to memory allocated.
  99. //
  100. // History: 17-Aug-92 PhilipLa Created.
  101. // 18-May-93 AlexT Switch to task IMalloc
  102. //
  103. //--------------------------------------------------------------------------
  104. inline void *CLocalAlloc::operator new(size_t size)
  105. {
  106. return TaskMemAlloc(size);
  107. }
  108. //+-------------------------------------------------------------------------
  109. //
  110. // Method: CLocalAlloc::operator delete, public
  111. //
  112. // Synopsis: Free memory from task local space
  113. //
  114. // Arguments: [pv] -- Pointer to memory to free
  115. //
  116. // History: 17-Aug-92 PhilipLa Created.
  117. // 18-May-93 AlexT Switch to task IMalloc
  118. //
  119. //--------------------------------------------------------------------------
  120. inline void CLocalAlloc::operator delete(void *pv)
  121. {
  122. TaskMemFree(pv);
  123. }
  124. #endif // DBG == 0 || defined(MULTIHEAP)
  125. // Use DfMemAlloc and DfMemFree for tempory allocations
  126. #define DfMemAlloc(cb) CLocalAlloc::operator new((size_t) (cb))
  127. #define DfMemFree(pv) delete (CLocalAlloc *) (pv)
  128. #endif // #ifndef __DFMEM_HXX__