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