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.

163 lines
3.8 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // File: cowblob.inl
  4. // Copyright (C) 1994-1997 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // Inline functions for CLocCOWBlob. This file should only be used by
  8. // cowblob.h
  9. //
  10. // Owner: MHotchin
  11. //
  12. // Code Review Status: Reviewed
  13. //
  14. //-----------------------------------------------------------------------------
  15. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  16. //
  17. // Constructor for the blob. Set the current size to zero.
  18. //
  19. //-----------------------------------------------------------------------------
  20. inline
  21. CLocCOWBlob::CLocCOWBlob()
  22. {
  23. m_pBuffer = NULL;
  24. m_WriteCount = 0;
  25. m_uiGrowSize = m_uiDefaultGrowSize;
  26. DEBUGONLY(++m_UsageCounter);
  27. }
  28. #ifdef LTASSERT_ACTIVE
  29. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  30. //
  31. // Returns the number of outstanding GetPointer()'s there are.
  32. // DEBUGONLY method!
  33. //
  34. //-----------------------------------------------------------------------------
  35. inline
  36. UINT
  37. CLocCOWBlob::GetWriteCount(void)
  38. const
  39. {
  40. return m_WriteCount;
  41. }
  42. #endif // _DEBUG
  43. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  44. //
  45. // Sets the granularity for memory allocations. Memory will always be
  46. // allocated in amounts that are a multiple of the GrowSize. This can be
  47. // useful if you are making small incremental reallocs - by setting a larger
  48. // grow size, you will allocate memory less often (but some may end up
  49. // being unused).
  50. //
  51. //-----------------------------------------------------------------------------
  52. inline
  53. void
  54. CLocCOWBlob::SetGrowSize(
  55. UINT uiGrowSize)
  56. {
  57. LTASSERT(uiGrowSize != 0);
  58. if (uiGrowSize == 0)
  59. {
  60. m_uiGrowSize = m_uiDefaultGrowSize;
  61. }
  62. else
  63. {
  64. m_uiGrowSize = uiGrowSize;
  65. }
  66. }
  67. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  68. //
  69. // Release a writable pointer. GetPointer and ReleasePointer should be
  70. // paired.
  71. //
  72. //-----------------------------------------------------------------------------
  73. inline
  74. void
  75. CLocCOWBlob::ReleasePointer(void)
  76. {
  77. LTASSERT(m_WriteCount != 0);
  78. if (m_WriteCount != 0)
  79. {
  80. m_WriteCount--;
  81. }
  82. }
  83. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  84. //
  85. // Return a read only pointer to storage.
  86. //
  87. //-----------------------------------------------------------------------------
  88. inline
  89. CLocCOWBlob::operator const void *(void)
  90. const
  91. {
  92. return DataPointer();
  93. }
  94. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  95. //
  96. // Destructor. Just detaches this blob from the user memory.
  97. //
  98. //-----------------------------------------------------------------------------
  99. inline
  100. CLocCOWBlob::~CLocCOWBlob()
  101. {
  102. DEBUGONLY(CLocCOWBlob::AssertValid());
  103. Detach();
  104. DEBUGONLY(--m_UsageCounter);
  105. }
  106. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  107. //
  108. // Is the data of this blob NOT equal to the data in the given blob?
  109. //
  110. //-----------------------------------------------------------------------------
  111. inline
  112. int //TRUE if both blobs are NOT identical
  113. CLocCOWBlob::operator!=(
  114. const CLocCOWBlob & SourceBlob)
  115. const
  116. {
  117. return !Compare(SourceBlob);
  118. }
  119. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  120. //
  121. // Is the data of this blob IS equal to the data in the given blob?
  122. //
  123. //-----------------------------------------------------------------------------
  124. inline
  125. int //TRUE if both blobs ARE identical
  126. CLocCOWBlob::operator==(
  127. const CLocCOWBlob & SourceBlob)
  128. const
  129. {
  130. return Compare(SourceBlob);
  131. }