Exemple #1
0
// GrowNoCopy
//------------------------------------------------------------------------------
void AString::GrowNoCopy( uint32_t newLength )
{
	if ( MemoryMustBeFreed() )
	{
		FREE( m_Contents );
	}

	// allocate space, rounded up to multiple of 2
	uint32_t reserve = Math::RoundUp( newLength, (uint32_t)2 );
	m_Contents = (char *)ALLOC( reserve + 1 ); // also allocate for \0 terminator
	SetReserved( reserve, true );
}
Exemple #2
0
// Grow
//------------------------------------------------------------------------------
void AString::Grow( uint32_t newLength )
{
	// allocate space, rounded up to multiple of 2
	uint32_t reserve = Math::RoundUp( newLength, (uint32_t)2 );
	char * newMem = (char *)ALLOC( reserve + 1 ); // also allocate for \0 terminator

	// transfer existing string data
	Copy( m_Contents, newMem, m_Length );

	if ( MemoryMustBeFreed() )
	{
		FREE( m_Contents );
	}

	m_Contents = newMem;
	SetReserved( reserve, true );
}
Exemple #3
0
// DESTRUCTOR
//------------------------------------------------------------------------------
AString::~AString()
{
	// At this point, we should
	if ( MemoryMustBeFreed() )
	{
		// if we own the memory, we must:
		// a) NOT be pointing to the shared global string
		ASSERT( m_Contents != s_EmptyString );
		// b) NOT be pointing to an internal buffer
		// Depending on the memory alloctor, it could be valid to have an allocation 
		// immediately after the string itself, causing this assert to fire incorrectly
		//ASSERT( (void *)m_Contents != (void *)( (char *)this + sizeof( AString ) ) );
		FREE( m_Contents );
	}
	else
	{
		// if we don't own the memory, either:
		// a) We are an empty string, pointing to the special global empty string
		// OR:
		// b) We are a StackString, and we should point to our internal buffer
		ASSERT( ( m_Contents == s_EmptyString ) ||
			    ( (void *)m_Contents == (void *)( (char *)this + sizeof( AString ) ) ) );
	}
}