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.

106 lines
1.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // File: cshalloc.cpp
  4. //
  5. // Contents: CSHAlloc
  6. //
  7. //--------------------------------------------------------------------------
  8. #include "shtl.h"
  9. #include <cshalloc.h>
  10. // CSHAlloc::QueryInterface
  11. __DATL_INLINE HRESULT CSHAlloc::QueryInterface(REFIID riid, void ** ppvObj)
  12. {
  13. *ppvObj = NULL;
  14. if (IsEqualIID(riid, IID_IMalloc))
  15. *ppvObj = (IMalloc *) this;
  16. return (*ppvObj) ? S_OK : E_NOINTERFACE;
  17. }
  18. // CSHAlloc::AddRef
  19. __DATL_INLINE ULONG CSHAlloc::AddRef()
  20. {
  21. return ++m_cRefs;
  22. }
  23. // CSHAlloc::Release
  24. __DATL_INLINE ULONG CSHAlloc::Release()
  25. {
  26. if (InterlockedDecrement((LONG *) &m_cRefs))
  27. {
  28. return 1;
  29. }
  30. else
  31. {
  32. delete this;
  33. return 0;
  34. }
  35. }
  36. // CSHAlloc Constructor
  37. //
  38. // Load the shell's allocator. Failure will cause subsequent allocs to fail.
  39. __DATL_INLINE CSHAlloc::CSHAlloc(BOOL bInitOle) : m_pMalloc(NULL)
  40. {
  41. // If you pass FALSE for this, you can't use it (you likely did so
  42. // just to avoid link errors)
  43. if (bInitOle)
  44. SHGetMalloc(&m_pMalloc);
  45. }
  46. __DATL_INLINE CSHAlloc::~CSHAlloc()
  47. {
  48. if (m_pMalloc)
  49. m_pMalloc->Release();
  50. }
  51. // CSHAlloc::Alloc
  52. __DATL_INLINE void * CSHAlloc::Alloc(SIZE_T cb)
  53. {
  54. return (m_pMalloc) ? m_pMalloc->Alloc(cb) : NULL;
  55. }
  56. // CSHAlloc::Free
  57. __DATL_INLINE void CSHAlloc::Free(void * pv)
  58. {
  59. if (m_pMalloc)
  60. m_pMalloc->Free(pv);
  61. }
  62. // CSHAlloc::Realloc
  63. __DATL_INLINE void * CSHAlloc::Realloc(void * pv, SIZE_T cb)
  64. {
  65. return (m_pMalloc) ? m_pMalloc->Realloc(pv, cb) : NULL;
  66. }
  67. // CSHAlloc::GetSize
  68. __DATL_INLINE SIZE_T CSHAlloc::GetSize(void * pv)
  69. {
  70. return (m_pMalloc) ? m_pMalloc->GetSize(pv) : 0;
  71. }
  72. // CSHAlloc::DidAlloc
  73. __DATL_INLINE int CSHAlloc::DidAlloc(void * pv)
  74. {
  75. return (m_pMalloc) ? m_pMalloc->DidAlloc(pv) : FALSE;
  76. }
  77. __DATL_INLINE void CSHAlloc::HeapMinimize()
  78. {
  79. if (m_pMalloc)
  80. m_pMalloc->HeapMinimize();
  81. }