Counter Strike : Global Offensive Source Code
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.

123 lines
3.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "pch_tier0.h"
  8. #include "vstdlib/pch_vstdlib.h"
  9. // NOTE: This has to be the last file included!
  10. #include "tier0/memdbgon.h"
  11. #ifdef DBGFLAG_VALIDATE
  12. //-----------------------------------------------------------------------------
  13. // Purpose: Initializer
  14. // Input: pchType - Type of the object we represent.
  15. // WARNING: pchType must be a static (since we keep a copy of it around for a while)
  16. // pvObj - Pointer to the object we represent
  17. // pchName - Name of the individual object we represent
  18. // WARNING: pchName must be a static (since we keep a copy of it around for a while)
  19. // pValObjectparent- Our parent object (ie, the object that our object is a member of)
  20. // pValObjectPrev - Object that precedes us in the linked list (we're
  21. // always added to the end)
  22. //-----------------------------------------------------------------------------
  23. void CValObject::Init( tchar *pchType, void *pvObj, tchar *pchName,
  24. CValObject *pValObjectParent, CValObject *pValObjectPrev )
  25. {
  26. m_nUser = 0;
  27. // Initialize pchType:
  28. if ( NULL != pchType )
  29. {
  30. Q_strncpy( m_rgchType, pchType, (int) ( sizeof(m_rgchType) / sizeof(*m_rgchType) ) );
  31. }
  32. else
  33. {
  34. m_rgchType[0] = '\0';
  35. }
  36. m_pvObj = pvObj;
  37. // Initialize pchName:
  38. if ( NULL != pchName )
  39. {
  40. Q_strncpy( m_rgchName, pchName, sizeof(m_rgchName) / sizeof(*m_rgchName) );
  41. }
  42. else
  43. {
  44. m_rgchName[0] = NULL;
  45. }
  46. m_pValObjectParent = pValObjectParent;
  47. if ( NULL == pValObjectParent )
  48. m_nLevel = 0;
  49. else
  50. m_nLevel = pValObjectParent->NLevel( ) + 1;
  51. m_cpubMemSelf = 0;
  52. m_cubMemSelf = 0;
  53. m_cpubMemTree = 0;
  54. m_cubMemTree = 0;
  55. // Insert us at the back of the linked list
  56. if ( NULL != pValObjectPrev )
  57. {
  58. Assert( NULL == pValObjectPrev->m_pValObjectNext );
  59. pValObjectPrev->m_pValObjectNext = this;
  60. }
  61. m_pValObjectNext = NULL;
  62. }
  63. //-----------------------------------------------------------------------------
  64. // Purpose: Destructor
  65. //-----------------------------------------------------------------------------
  66. CValObject::~CValObject( )
  67. {
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose: The object we represent has claimed direct ownership of a block of
  71. // memory. Record that we own it.
  72. // Input: pvMem - Address of the memory block
  73. //-----------------------------------------------------------------------------
  74. void CValObject::ClaimMemoryBlock( void *pvMem )
  75. {
  76. // Get the memory block header
  77. CMemBlockHdr *pMemBlockHdr = CMemBlockHdr::PMemBlockHdrFromPvUser( pvMem );
  78. pMemBlockHdr->CheckValid( );
  79. // Update our counters
  80. m_cpubMemSelf++;
  81. m_cubMemSelf+= pMemBlockHdr->CubUser( );
  82. m_cpubMemTree++;
  83. m_cubMemTree+= pMemBlockHdr->CubUser( );
  84. // If we have a parent object, let it know about the memory (it'll recursively call up the tree)
  85. if ( NULL != m_pValObjectParent )
  86. m_pValObjectParent->ClaimChildMemoryBlock( pMemBlockHdr->CubUser( ) );
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose: A child of ours has claimed ownership of a memory block. Make
  90. // a note of it, and pass the message back up the tree.
  91. // Input: cubUser - Size of the memory block
  92. //-----------------------------------------------------------------------------
  93. void CValObject::ClaimChildMemoryBlock( int cubUser )
  94. {
  95. m_cpubMemTree++;
  96. m_cubMemTree += cubUser;
  97. if ( NULL != m_pValObjectParent )
  98. m_pValObjectParent->ClaimChildMemoryBlock( cubUser );
  99. }
  100. #endif // DBGFLAG_VALIDATE