Hello:
I'm getting some odd behavior in one of my class members and it is truly throwing me for a loop but I'm certainly not seeing the issue (long week!)
void MyFakeStringClass::readStream( iostream& nInputStream )
{
// Hold the string size
UINT32 size = 0;
// Read the size from the stream
nInputStream.read( reinterpret_cast< char* >( &size ), sizeof( UINT32 ) );
// Create a new buffer
char* buffer = new char[ size ];
// Read the stream
nInputStream.read( buffer, size );
// Save to class member
value = string( buffer );
// Clean up
delete[] buffer;
buffer = NULL;
}
This issue arises when I use two or more MyFakeStringClass's. buffer
is somehow still containing data from previous calls to MyFakeStringClass::readStream
.
Say for example I read in two strings 'HelloWorld', 'Test' the resulting MyFakeStringClass objects contain 'HelloWorld', and 'TestoWorld' ( should be 'HelloWorld', 'Test' ).
The second time the function is accessed buffer
is still containing 'old' memory. How is this possible as it is locally scoped and deleted? I've confirmed that buffer
is being somehow shared with a debugger.