CString的麻烦
精锐掷矛手 2010-01-04 09:13:20 struct CStringData
{
IAtlStringMgr* pStringMgr; // String manager for this CStringData
int nDataLength; // Length of currently used data in XCHARs (not including terminating null)
int nAllocLength; // Length of allocated data in XCHARs (not including terminating null)
long nRefs; // Reference count: negative == locked
// XCHAR data[nAllocLength+1] // A CStringData is always followed in memory by the actual array of character data
void* data() throw()
{
return (this+1);
}
void AddRef() throw()
{
ATLASSERT(nRefs > 0);
_AtlInterlockedIncrement(&nRefs);
}
bool IsLocked() const throw()
{
return nRefs < 0;
}
bool IsShared() const throw()
{
return( nRefs > 1 ); //在这出现错误
}
void Lock() throw()
{
ATLASSERT( nRefs <= 1 );
nRefs--; // Locked buffers can't be shared, so no interlocked operation necessary
if( nRefs == 0 )
{
nRefs = -1;
}
}
void Release() throw()
{
ATLASSERT( nRefs != 0 );
if( _AtlInterlockedDecrement( &nRefs ) <= 0 )
{
pStringMgr->Free( this );
}
}
void Unlock() throw()
{
ATLASSERT( IsLocked() );
if(IsLocked())
{
nRefs++; // Locked buffers can't be shared, so no interlocked operation necessary
if( nRefs == 0 )
{
nRefs = 1;
}
}
}
};
我想问一下,此类错误都是什么引起的。我写的程序总在运行一段后出现这个错误?