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.

878 lines
22 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: heap.hxx
  7. //
  8. // Contents: Heap code headers
  9. //
  10. // Classes: CHeap
  11. //
  12. // History: 29-Mar-94 PhilipLa Created
  13. // 05-Feb-95 KentCe Use Win95 Shared Heap.
  14. // 10-Apr095 HenryLee Added global LUID
  15. // 10-May-95 KentCe Defer Heap Destruction to the last
  16. // process detach.
  17. //
  18. //----------------------------------------------------------------------------
  19. #ifndef __HEAP_HXX__
  20. #define __HEAP_HXX__
  21. #include <smblock.hxx>
  22. #include <memdebug.hxx>
  23. #include <smmutex.hxx>
  24. #include <msf.hxx>
  25. #include <df32.hxx>
  26. #ifdef COORD
  27. #include <dfrlist.hxx>
  28. #endif
  29. //Space to reserve for heap.
  30. const ULONG MINHEAPGROWTH = 4096;
  31. const ULONG INITIALHEAPSIZE = 16384;
  32. #ifdef MULTIHEAP
  33. #include <ntpsapi.h>
  34. class CPerContext;
  35. #endif
  36. //+-------------------------------------------------------------------------
  37. //
  38. // Class: CLockDfMutex
  39. //
  40. // Purpose: Simple class to guarantee that a DfMutex is unlocked
  41. //
  42. // History: 29-Apr-95 DonnaLi Created
  43. //
  44. //--------------------------------------------------------------------------
  45. class CLockDfMutex
  46. {
  47. public:
  48. CLockDfMutex(CDfMutex& dmtx);
  49. ~CLockDfMutex(void);
  50. private:
  51. CDfMutex& _dmtx;
  52. };
  53. //+-------------------------------------------------------------------------
  54. //
  55. // Member: CLockDfMutex::CLockDfMutex
  56. //
  57. // Synopsis: Get mutex
  58. //
  59. // Arguments: [dmtx] -- mutex to get
  60. //
  61. // History: 29-Apr-95 DonnaLi Created
  62. //
  63. //--------------------------------------------------------------------------
  64. inline CLockDfMutex::CLockDfMutex(CDfMutex& dmtx) : _dmtx(dmtx)
  65. {
  66. _dmtx.Take(DFM_TIMEOUT);
  67. }
  68. //+-------------------------------------------------------------------------
  69. //
  70. // Member: CLockDfMutex::~CLockDfMutex
  71. //
  72. // Synopsis: Release the mutex
  73. //
  74. // History: 29-Apr-95 DonnaLi Created
  75. //
  76. //--------------------------------------------------------------------------
  77. inline CLockDfMutex::~CLockDfMutex(void)
  78. {
  79. _dmtx.Release();
  80. }
  81. //
  82. // Take advantage of Windows 95 Shared Heap.
  83. //
  84. #if !defined(_CHICAGO_)
  85. //+---------------------------------------------------------------------------
  86. //
  87. // Class: CBlockPreHeader
  88. //
  89. // Purpose: Required header fields for a block
  90. //
  91. // History: 29-Mar-94 PhilipLa Created
  92. //
  93. //----------------------------------------------------------------------------
  94. class CBlockPreHeader
  95. {
  96. protected:
  97. SIZE_T _ulSize; //Size of block
  98. BOOL _fFree; //TRUE if block is free
  99. };
  100. //+---------------------------------------------------------------------------
  101. //
  102. // Class: CBlockHeader
  103. //
  104. // Purpose: Fields required for free blocks but overwritten for
  105. // allocated blocks.
  106. //
  107. // History: 29-Mar-94 PhilipLa Created
  108. //
  109. //----------------------------------------------------------------------------
  110. class CBlockHeader: public CBlockPreHeader
  111. {
  112. public:
  113. inline SIZE_T GetSize(void) const;
  114. inline BOOL IsFree(void) const;
  115. inline SIZE_T GetNext(void) const;
  116. inline void SetSize(SIZE_T ulSize);
  117. inline void SetFree(void);
  118. inline void ResetFree(void);
  119. inline void SetNext(SIZE_T ulNext);
  120. private:
  121. SIZE_T _ulNext; //Pointer to next block
  122. };
  123. //+---------------------------------------------------------------------------
  124. //
  125. // Member: CBlockHeader::GetSize, public
  126. //
  127. // Synopsis: Returns the size of the block
  128. //
  129. // History: 30-Mar-94 PhilipLa Created
  130. //
  131. //----------------------------------------------------------------------------
  132. inline SIZE_T CBlockHeader::GetSize(void) const
  133. {
  134. return _ulSize;
  135. }
  136. //+---------------------------------------------------------------------------
  137. //
  138. // Member: CBlockHeader::IsFree, public
  139. //
  140. // Synopsis: Returns free state of block
  141. //
  142. // History: 30-Mar-94 PhilipLa Created
  143. //
  144. //----------------------------------------------------------------------------
  145. inline BOOL CBlockHeader::IsFree(void) const
  146. {
  147. memAssert (_fFree == TRUE || _fFree == FALSE); // check for corruption
  148. return _fFree;
  149. }
  150. //+---------------------------------------------------------------------------
  151. //
  152. // Member: CBlockHeader::GetNext, public
  153. //
  154. // Synopsis: Return next offset
  155. //
  156. // History: 30-Mar-94 PhilipLa Created
  157. //
  158. //----------------------------------------------------------------------------
  159. inline SIZE_T CBlockHeader::GetNext(void) const
  160. {
  161. return _ulNext;
  162. }
  163. //+---------------------------------------------------------------------------
  164. //
  165. // Member: CBlockHeader::SetSize, public
  166. //
  167. // Synopsis: Set size of block
  168. //
  169. // History: 30-Mar-94 PhilipLa Created
  170. //
  171. //----------------------------------------------------------------------------
  172. inline void CBlockHeader::SetSize(SIZE_T ulSize)
  173. {
  174. _ulSize = ulSize;
  175. }
  176. //+---------------------------------------------------------------------------
  177. //
  178. // Member: CBlockHeader::SetFree, public
  179. //
  180. // Synopsis: Set this block to free
  181. //
  182. // History: 30-Mar-94 PhilipLa Created
  183. //
  184. //----------------------------------------------------------------------------
  185. inline void CBlockHeader::SetFree(void)
  186. {
  187. _fFree = TRUE;
  188. }
  189. //+---------------------------------------------------------------------------
  190. //
  191. // Member: CBlockHeader::ResetFree, public
  192. //
  193. // Synopsis: Set this block to !free
  194. //
  195. // History: 30-Mar-94 PhilipLa Created
  196. //
  197. //----------------------------------------------------------------------------
  198. inline void CBlockHeader::ResetFree(void)
  199. {
  200. _fFree = FALSE;
  201. }
  202. //+---------------------------------------------------------------------------
  203. //
  204. // Member: CBlockHeader::SetNext, public
  205. //
  206. // Synopsis: Set next offset
  207. //
  208. // History: 30-Mar-94 PhilipLa Created
  209. //
  210. //----------------------------------------------------------------------------
  211. inline void CBlockHeader::SetNext(SIZE_T ulNext)
  212. {
  213. _ulNext = ulNext;
  214. }
  215. const ULONG CBLOCKMIN = ((sizeof(CBlockHeader) & 7)
  216. ? sizeof(CBlockHeader) +
  217. (8 - (sizeof(CBlockHeader) & 7))
  218. : sizeof(CBlockHeader));
  219. //+---------------------------------------------------------------------------
  220. //
  221. // Class: CHeapHeader
  222. //
  223. // Purpose: Header information for shared memory heap
  224. //
  225. // Interface:
  226. //
  227. // History: 30-Mar-94 PhilipLa Created
  228. //
  229. // Notes: The size of this structure must be a multiple of 8 bytes.
  230. //
  231. //----------------------------------------------------------------------------
  232. class CHeapHeader
  233. {
  234. public:
  235. inline SIZE_T GetFirstFree(void) const;
  236. inline void SetFirstFree(SIZE_T ulNew);
  237. inline BOOL IsCompacted(void) const;
  238. inline void SetCompacted(void);
  239. inline void ResetCompacted(void);
  240. inline void ResetAllocedBlocks(void);
  241. inline SIZE_T IncrementAllocedBlocks(void);
  242. inline SIZE_T DecrementAllocedBlocks(void);
  243. inline SIZE_T GetAllocedBlocks(void);
  244. inline DFLUID IncrementLuid(void);
  245. inline void ResetLuid(void);
  246. #if DBG == 1
  247. SIZE_T _ulAllocedBytes;
  248. SIZE_T _ulFreeBytes;
  249. SIZE_T _ulFreeBlocks;
  250. #endif
  251. private:
  252. SIZE_T _ulFirstFree;
  253. SIZE_T _ulAllocedBlocks;
  254. BOOL _fIsCompacted;
  255. DFLUID _dfLuid;
  256. #if DBG == 1
  257. SIZE_T ulPad;
  258. #endif
  259. };
  260. //+---------------------------------------------------------------------------
  261. //
  262. // Member: CHeapHeader::GetFirstFree, public
  263. //
  264. // Synopsis: Return first free information
  265. //
  266. // History: 30-Mar-94 PhilipLa Created
  267. //
  268. //----------------------------------------------------------------------------
  269. inline SIZE_T CHeapHeader::GetFirstFree(void) const
  270. {
  271. return _ulFirstFree;
  272. }
  273. //+---------------------------------------------------------------------------
  274. //
  275. // Member: CHeapHeader::SetFirstFree, public
  276. //
  277. // Synopsis: Set first free information
  278. //
  279. // History: 30-Mar-94 PhilipLa Created
  280. //
  281. //----------------------------------------------------------------------------
  282. inline void CHeapHeader::SetFirstFree(SIZE_T ulNew)
  283. {
  284. _ulFirstFree = ulNew;
  285. }
  286. //+---------------------------------------------------------------------------
  287. //
  288. // Member: CHeapHeader::IsCompacted, public
  289. //
  290. // Synopsis: Return TRUE if heap is compacted
  291. //
  292. // History: 30-Mar-94 PhilipLa Created
  293. //
  294. //----------------------------------------------------------------------------
  295. inline BOOL CHeapHeader::IsCompacted(void) const
  296. {
  297. return _fIsCompacted;
  298. }
  299. //+---------------------------------------------------------------------------
  300. //
  301. // Member: CHeapHeader::SetCompacted, public
  302. //
  303. // Synopsis: Set compacted bit
  304. //
  305. // History: 30-Mar-94 PhilipLa Created
  306. //
  307. //----------------------------------------------------------------------------
  308. inline void CHeapHeader::SetCompacted(void)
  309. {
  310. _fIsCompacted = TRUE;
  311. }
  312. //+---------------------------------------------------------------------------
  313. //
  314. // Member: CHeapHeader::ResetCompacted, public
  315. //
  316. // Synopsis: Reset compacted bit
  317. //
  318. // History: 30-Mar-94 PhilipLa Created
  319. //
  320. //----------------------------------------------------------------------------
  321. inline void CHeapHeader::ResetCompacted(void)
  322. {
  323. _fIsCompacted = FALSE;
  324. }
  325. //+---------------------------------------------------------------------------
  326. //
  327. // Member: CHeapHeader::IncrementLuid, public
  328. //
  329. // Synopsis: Increment the global LUID
  330. //
  331. // History: 06-Apr-95 HenryLee Created
  332. //
  333. //----------------------------------------------------------------------------
  334. inline ULONG CHeapHeader::IncrementLuid()
  335. {
  336. return ++_dfLuid;
  337. }
  338. //+---------------------------------------------------------------------------
  339. //
  340. // Member: CHeapHeader::ResetLuid, public
  341. //
  342. // Synopsis: Increment the global LUID
  343. //
  344. // History: 06-Apr-95 HenryLee Created
  345. //
  346. //----------------------------------------------------------------------------
  347. inline void CHeapHeader::ResetLuid()
  348. {
  349. _dfLuid = LUID_BASE; // some LUIDs are reserved
  350. }
  351. #ifdef MULTIHEAP
  352. extern DFLUID gs_dfluid; // task memory support
  353. extern INT gs_iSharedHeaps; // number ofshared heaps
  354. #endif
  355. #else // define(_CHICAGO_)
  356. extern HANDLE gs_hSharedHeap; // hSharedHeap Handle for Win95.
  357. extern DFLUID gs_dfluid; // shared docfile LUID
  358. #endif // !define(_CHICAGO_)
  359. //+---------------------------------------------------------------------------
  360. //
  361. // Class: CSmAllocator
  362. //
  363. // Purpose: Shared memory heap implementation
  364. //
  365. // History: 29-Mar-94 PhilipLa Created
  366. // 05-Feb-95 KentCe Use Win95 Shared Heap.
  367. //
  368. //----------------------------------------------------------------------------
  369. class CSmAllocator: public IMalloc
  370. {
  371. public:
  372. inline CSmAllocator();
  373. inline ~CSmAllocator();
  374. STDMETHOD_(ULONG,AddRef) ( void );
  375. STDMETHOD_(ULONG,Release) ( void );
  376. STDMETHOD(QueryInterface) ( REFIID riid, void ** ppv );
  377. STDMETHOD_(void*,Alloc) ( SIZE_T cb );
  378. STDMETHOD_(void *,Realloc) ( void *pvCurrent, SIZE_T cbNeeded );
  379. STDMETHOD_(void,Free) ( void *pvMemToFree );
  380. STDMETHOD_(SIZE_T,GetSize) ( void * pv );
  381. STDMETHOD_(void,HeapMinimize) ( void );
  382. STDMETHOD_(int,DidAlloc) ( void * pv );
  383. inline SCODE Sync(void);
  384. inline DFLUID IncrementLuid(void);
  385. #if !defined(MULTIHEAP)
  386. SCODE Init ( LPWSTR pszName );
  387. #else
  388. SCODE Init ( ULONG ulHeapName, BOOL fUnmarshal );
  389. #endif
  390. inline void * GetBase(void);
  391. // This function is equivalent to Free above, except that is does
  392. // not attempt to first acquire the mutex. It should be used ONLY
  393. // when the calling function guarantees to already have the mutex.
  394. void FreeNoMutex (void * pv);
  395. #if !defined(MULTIHEAP)
  396. inline CDfMutex * GetMutex (void);
  397. #endif
  398. #ifdef MULTIHEAP
  399. void SetState (CSharedMemoryBlock *psmb, BYTE * pbBase,
  400. ULONG ulHeapName, CPerContext ** ppcPrev,
  401. CPerContext *ppcOwner);
  402. void GetState (CSharedMemoryBlock **ppsmb, BYTE ** ppbBase,
  403. ULONG *pulHeapName);
  404. inline const ULONG GetHeapName ();
  405. SCODE Uninit ();
  406. inline const ULONG GetHeapSize () { return _cbSize; };
  407. #if DBG == 1
  408. void PrintAllocatedBlocks(void);
  409. #endif
  410. #endif
  411. private:
  412. inline void DoFree (void *pv);
  413. #if !defined(MULTIHEAP)
  414. CDfMutex _dmtx;
  415. #endif
  416. //
  417. // Take advantage of Windows 95 Shared Heap.
  418. //
  419. #if !defined(_CHICAGO_)
  420. CBlockHeader * FindBlock(SIZE_T cb, CBlockHeader **ppbhPrev);
  421. inline CHeapHeader *GetHeader(void);
  422. inline CBlockHeader * GetAddress(SIZE_T ulOffset) const;
  423. inline ULONG GetOffset(CBlockHeader *pbh) const;
  424. inline SCODE Reset(void);
  425. #if DBG == 1
  426. void PrintFreeBlocks(void);
  427. #endif
  428. #ifdef MULTIHEAP
  429. CSharedMemoryBlock *_psmb;
  430. BYTE *_pbBase;
  431. ULONG _cbSize;
  432. CPerContext * _ppcOwner;
  433. ULONG _ulHeapName;
  434. ULONG _cRefs; // yes, this object has a lifetime now
  435. #else
  436. CSharedMemoryBlock _smb;
  437. BYTE *_pbBase;
  438. SIZE_T _cbSize;
  439. #endif // MULTIHEAP
  440. #else // defined(_CHICAGO_)
  441. HANDLE m_hSharedHeap;
  442. #endif // !defined(_CHICAGO_)
  443. };
  444. #ifdef MULTIHEAP
  445. extern CSmAllocator g_SmAllocator; // single-threaded allocator
  446. extern CSharedMemoryBlock g_smb; //performance optimization
  447. extern ULONG g_ulHeapName;
  448. extern CSmAllocator& GetTlsSmAllocator(); // all other threads
  449. extern TEB * g_pteb;
  450. #define g_smAllocator (GetTlsSmAllocator())
  451. //+---------------------------------------------------------------------------
  452. //
  453. // Class: CErrorSmAllocator
  454. //
  455. // Synopsis: returned by GetTlsSmAllocator for out of memory failures
  456. //
  457. // History: 02-May-1996 HenryLee Created
  458. //
  459. //----------------------------------------------------------------------------
  460. class CErrorSmAllocator : public CSmAllocator
  461. {
  462. public:
  463. STDMETHOD_(void*,Alloc) (SIZE_T cb) { return NULL; };
  464. STDMETHOD_(void*,Realloc) (void* pv, SIZE_T cb) { return NULL; };
  465. STDMETHOD_(void,Free) (void *pv) { return; };
  466. STDMETHOD_(SIZE_T,GetSize) (void *pv) { return 0; };
  467. STDMETHOD_(void,HeapMinimize) () { return; };
  468. STDMETHOD_(int,DidAlloc) (void *pv) { return FALSE; };
  469. SCODE Init (ULONG ul, BOOL f) { return STG_E_INSUFFICIENTMEMORY; };
  470. SCODE Sync (void) { return STG_E_INSUFFICIENTMEMORY; };
  471. };
  472. extern CErrorSmAllocator g_ErrorSmAllocator;
  473. extern IMalloc * g_pTaskAllocator;
  474. #else
  475. extern CSmAllocator g_smAllocator;
  476. #endif
  477. extern CRITICAL_SECTION g_csScratchBuffer;
  478. //+---------------------------------------------------------------------------
  479. //
  480. // Member: CSmAllocator::CSmAllocator, public
  481. //
  482. // Synopsis: Constructor
  483. //
  484. // History: 29-Mar-94 PhilipLa Created
  485. // 05-Feb-95 KentCe Use Win95 Shared Heap.
  486. //
  487. //----------------------------------------------------------------------------
  488. inline CSmAllocator::CSmAllocator(void)
  489. #if !defined(_CHICAGO_)
  490. #ifdef MULTIHEAP
  491. : _cbSize(0), _pbBase(NULL), _cRefs(1), _ulHeapName(0),
  492. _psmb(NULL), _ppcOwner(NULL)
  493. #else
  494. : _cbSize(0)
  495. #endif // MULTIHEAP
  496. #else
  497. : m_hSharedHeap(NULL)
  498. #endif
  499. {
  500. #if !defined(MULTIHEAP)
  501. InitializeCriticalSection(&g_csScratchBuffer);
  502. #ifdef COORD
  503. InitializeCriticalSection(&g_csResourceList);
  504. #endif
  505. #endif // MULTIHEAP
  506. }
  507. //+---------------------------------------------------------------------------
  508. //
  509. // Member: CSmAllocator::~CSmAllocator, public
  510. //
  511. // Synopsis: Destructor
  512. //
  513. // History: 29-Mar-94 PhilipLa Created
  514. // 05-Feb-95 KentCe Use Win95 Shared Heap.
  515. // 10-May-95 KentCe Defer Heap Destruction to the last
  516. // process detach.
  517. //
  518. //----------------------------------------------------------------------------
  519. inline CSmAllocator::~CSmAllocator(void)
  520. {
  521. #if !defined(MULTIHEAP)
  522. DeleteCriticalSection(&g_csScratchBuffer);
  523. #ifdef COORD
  524. DeleteCriticalSection(&g_csResourceList);
  525. #endif
  526. #endif // MULTIHEAP
  527. }
  528. //+---------------------------------------------------------------------------
  529. //
  530. // Member: CSmAllocator::Sync, public
  531. //
  532. // Synopsis: Sync memory to global state.
  533. //
  534. // Arguments: None.
  535. //
  536. // Returns: Appropriate status code
  537. //
  538. // History: 29-Mar-94 PhilipLa Created
  539. // 05-Feb-95 KentCe Use Win95 Shared Heap.
  540. //
  541. //----------------------------------------------------------------------------
  542. inline SCODE CSmAllocator::Sync(void)
  543. {
  544. SCODE sc = S_OK;
  545. #if !defined(_CHICAGO_)
  546. #if !defined(MULTIHEAP)
  547. if (!_smb.IsSynced())
  548. {
  549. CLockDfMutex lckdmtx(_dmtx);
  550. sc = _smb.Sync();
  551. _cbSize = _smb.GetSize();
  552. }
  553. #else
  554. if (_psmb)
  555. {
  556. if (!_psmb->IsSynced())
  557. {
  558. sc = _psmb->Sync();
  559. }
  560. _cbSize = _psmb->GetSize();
  561. }
  562. #endif
  563. #endif
  564. return sc;
  565. }
  566. //+---------------------------------------------------------------------------
  567. //
  568. // Member: CSmAllocator::IncrementLuid, public
  569. //
  570. // Synopsis: Increments the global LUID
  571. //
  572. // Arguments: None.
  573. //
  574. // Returns: Appropriate status code
  575. //
  576. // History: 06-Apr-95 HenryLee Created
  577. //----------------------------------------------------------------------------
  578. inline DFLUID CSmAllocator::IncrementLuid(void)
  579. {
  580. #if !defined(MULTIHEAP)
  581. CLockDfMutex lckdmx(_dmtx);
  582. #endif
  583. #ifdef _CHICAGO_
  584. //
  585. // On Chicago, we merely increment the globally available
  586. // LUID to the next value.
  587. //
  588. return ++gs_dfluid;
  589. #else
  590. return _pbBase ? GetHeader()->IncrementLuid() :
  591. InterlockedIncrement((LONG*)&gs_dfluid);
  592. #endif
  593. }
  594. //+---------------------------------------------------------------------------
  595. //
  596. // Member: CSmAllocator::GetBase, public
  597. //
  598. // Synopsis: Return pointer to base of heap
  599. //
  600. // History: 29-Mar-94 PhilipLa Created
  601. // 05-Feb-95 KentCe Use Win95 Shared Heap.
  602. //
  603. //----------------------------------------------------------------------------
  604. inline void * CSmAllocator::GetBase(void)
  605. {
  606. #if defined(_CHICAGO_)
  607. return NULL;
  608. #else
  609. return _pbBase;
  610. #endif
  611. }
  612. #if !defined(MULTIHEAP)
  613. //+---------------------------------------------------------------------------
  614. //
  615. // Member: CSmAllocator::GetMutex, public
  616. //
  617. // Synopsis: Return a pointer to the Mutex
  618. //
  619. // History: 19-Jul-95 SusiA Created
  620. //
  621. //----------------------------------------------------------------------------
  622. inline CDfMutex * CSmAllocator::GetMutex(void)
  623. {
  624. return &_dmtx;
  625. }
  626. #endif
  627. //
  628. // Take advantage of Windows 95 Shared Heap.
  629. //
  630. #if !defined(_CHICAGO_)
  631. //+---------------------------------------------------------------------------
  632. //
  633. // Member: CSmAllocator::GetAddress, private
  634. //
  635. // Synopsis: Returns an address given an offset from the base
  636. //
  637. // Arguments: [ulOffset] -- Offset to convert to address
  638. //
  639. // History: 29-Mar-94 PhilipLa Created
  640. //
  641. //----------------------------------------------------------------------------
  642. inline CBlockHeader * CSmAllocator::GetAddress(SIZE_T ulOffset) const
  643. {
  644. return (ulOffset == 0) ? NULL : (CBlockHeader *)(_pbBase + ulOffset);
  645. }
  646. //+---------------------------------------------------------------------------
  647. //
  648. // Member: CSmAllocator::GetOffset
  649. //
  650. // Synopsis: Returns a byte offset from the base given a pointer
  651. //
  652. // Arguments: [pbh] -- Pointer to convert to offset
  653. //
  654. // History: 29-Mar-94 PhilipLa Created
  655. //
  656. //----------------------------------------------------------------------------
  657. inline ULONG CSmAllocator::GetOffset(CBlockHeader *pbh) const
  658. {
  659. memAssert((BYTE *)pbh >= _pbBase && (BYTE*)pbh < _pbBase + _cbSize);
  660. return (ULONG)((ULONG_PTR)pbh - (ULONG_PTR)_pbBase);
  661. }
  662. //+---------------------------------------------------------------------------
  663. //
  664. // Member: CSmAllocator::GetHeader, private
  665. //
  666. // Synopsis: Return pointer to CHeapHeader for this heap
  667. //
  668. // History: 30-Mar-94 PhilipLa Created
  669. //
  670. //----------------------------------------------------------------------------
  671. inline CHeapHeader * CSmAllocator::GetHeader(void)
  672. {
  673. return (CHeapHeader *)_pbBase;
  674. }
  675. #ifdef MULTIHEAP
  676. //+-------------------------------------------------------------------------
  677. //
  678. // Member: CSmAllocator::HeapName, public
  679. //
  680. // Synopsis: Return the luid part of the shared heap name
  681. //
  682. // History: 30-Nov-95 HenryLee Created
  683. //
  684. //--------------------------------------------------------------------------
  685. inline const ULONG CSmAllocator::GetHeapName()
  686. {
  687. return _ulHeapName;
  688. }
  689. #endif
  690. //+---------------------------------------------------------------------------
  691. //
  692. // Member: CHeapHeader::ResetAllocedBlocks, public
  693. //
  694. // Synopsis: Reset the allocated block counter
  695. //
  696. // History: 04-Apr-94 PhilipLa Created
  697. //
  698. //----------------------------------------------------------------------------
  699. inline void CHeapHeader::ResetAllocedBlocks(void)
  700. {
  701. _ulAllocedBlocks = 0;
  702. }
  703. //+---------------------------------------------------------------------------
  704. //
  705. // Member: CHeapHeader::IncrementAllocedBlocks, public
  706. //
  707. // Synopsis: Increment the allocated block count
  708. //
  709. // History: 04-Apr-94 PhilipLa Created
  710. //
  711. //----------------------------------------------------------------------------
  712. inline SIZE_T CHeapHeader::IncrementAllocedBlocks(void)
  713. {
  714. return ++_ulAllocedBlocks;
  715. }
  716. //+---------------------------------------------------------------------------
  717. //
  718. // Member: CHeapHeader::DecrementAllocedBlocks, public
  719. //
  720. // Synopsis: Decrement the allocated block count
  721. //
  722. // History: 04-Apr-94 PhilipLa Created
  723. //
  724. //----------------------------------------------------------------------------
  725. inline SIZE_T CHeapHeader::DecrementAllocedBlocks(void)
  726. {
  727. return --_ulAllocedBlocks;
  728. }
  729. //+---------------------------------------------------------------------------
  730. //
  731. // Member: CHeapHeader::GetAllocedBlocks, public
  732. //
  733. // Synopsis: Return the allocated block count
  734. //
  735. // History: 04-Apr-94 PhilipLa Created
  736. //
  737. //----------------------------------------------------------------------------
  738. inline SIZE_T CHeapHeader::GetAllocedBlocks(void)
  739. {
  740. return _ulAllocedBlocks;
  741. }
  742. #endif // !defined(_CHICAGO_)
  743. #endif // #ifndef __HEAP_HXX__