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.

115 lines
4.2 KiB

  1. // --------------------------------------------------------------------------------
  2. // Objheap.cpp
  3. // Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  4. // Steven J. Bailey
  5. // --------------------------------------------------------------------------------
  6. #include "pch.hxx"
  7. #include "objheap.h"
  8. #include "dllmain.h"
  9. #include "containx.h"
  10. #include "stddef.h"
  11. #include "objpool.h"
  12. // --------------------------------------------------------------------------------
  13. // Object Heap Limits
  14. // --------------------------------------------------------------------------------
  15. #define COBJHEAPMAX_BODY 100
  16. #define COBJHEAPMAX_ADDR 100
  17. #define COBJHEAPMAX_PROP 200
  18. // --------------------------------------------------------------------------------
  19. // Object Heap Definitions
  20. // --------------------------------------------------------------------------------
  21. class CPropAlloc : public CAllocObjWithIMalloc<PROPERTY,offsetof(PROPERTY,pNextValue)>
  22. {
  23. public:
  24. static void CleanObject(PROPERTY *pProperty) {
  25. // Free name ?
  26. if (ISFLAGSET(pProperty->dwState, PRSTATE_ALLOCATED) && pProperty->pbBlob)
  27. {
  28. Assert(pProperty->pbBlob != pProperty->rgbScratch);
  29. g_pMalloc->Free(pProperty->pbBlob);
  30. pProperty->pbBlob = NULL;
  31. }
  32. // Release Address Group
  33. SafeMemFree(pProperty->pGroup);
  34. CAllocObjWithIMalloc<PROPERTY,offsetof(PROPERTY,pNextValue)>::CleanObject(pProperty);
  35. };
  36. };
  37. class CAddrAlloc : public CAllocObjWithIMalloc<MIMEADDRESS,offsetof(MIMEADDRESS,pNext)>
  38. {
  39. public:
  40. static void CleanObject(MIMEADDRESS *pAddress) {
  41. MimeAddressFree(pAddress);
  42. // We don't actually need to do this - since the base object's
  43. // CleanObject() just does a memset(), and the MimeAddressFree()
  44. // method above also does a memset(). So we'll just comment it
  45. // out, and save outselves the bandwidth on the memory bus...
  46. // CAllocObjWithIMalloc<MIMEADDRESS,g_pMalloc>::CleanObject(pAddress);
  47. };
  48. };
  49. static CAutoObjPoolMulti<PROPERTY,offsetof(PROPERTY,pNextValue),CPropAlloc> g_PropPool;
  50. static CAutoObjPool<MIMEADDRESS,offsetof(MIMEADDRESS,pNext),CAddrAlloc> g_AddrPool;
  51. // ---------------------------------------------------------------------------
  52. // InitObjectHeaps
  53. // ---------------------------------------------------------------------------
  54. void InitObjectHeaps(void)
  55. {
  56. g_PropPool.Init(COBJHEAPMAX_PROP);
  57. g_AddrPool.Init(COBJHEAPMAX_ADDR);
  58. }
  59. // ---------------------------------------------------------------------------
  60. // FreeObjectHeaps
  61. // ---------------------------------------------------------------------------
  62. void FreeObjectHeaps(void)
  63. {
  64. g_AddrPool.Term();
  65. g_PropPool.Term();
  66. }
  67. // ---------------------------------------------------------------------------
  68. // ObjectHeap_HrAllocProperty
  69. // ---------------------------------------------------------------------------
  70. HRESULT ObjectHeap_HrAllocProperty(LPPROPERTY *ppProperty)
  71. {
  72. *ppProperty = g_PropPool.GetFromPool();
  73. if (NULL == *ppProperty)
  74. return TrapError(E_OUTOFMEMORY);
  75. return S_OK;
  76. }
  77. // --------------------------------------------------------------------------------
  78. // ObjectHeap_HrAllocAddress
  79. // --------------------------------------------------------------------------------
  80. HRESULT ObjectHeap_HrAllocAddress(LPMIMEADDRESS *ppAddress)
  81. {
  82. *ppAddress = g_AddrPool.GetFromPool();
  83. if (NULL == *ppAddress)
  84. return TrapError(E_OUTOFMEMORY);
  85. return S_OK;
  86. }
  87. // ---------------------------------------------------------------------------
  88. // ObjectHeap_FreeProperty
  89. // ---------------------------------------------------------------------------
  90. void ObjectHeap_FreeProperty(LPPROPERTY pProperty)
  91. {
  92. g_PropPool.AddToPool(pProperty);
  93. }
  94. // ---------------------------------------------------------------------------
  95. // ObjectHeap_FreeAddress
  96. // ---------------------------------------------------------------------------
  97. void ObjectHeap_FreeAddress(LPMIMEADDRESS pAddress)
  98. {
  99. g_AddrPool.AddToPool(pAddress);
  100. }