Team Fortress 2 Source Code as on 22/4/2020
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.

119 lines
3.5 KiB

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