mirror of
https://github.com/dashr9230/SA-MP.git
synced 2024-12-22 22:47:29 +08:00
[raknet] Implement BitStream::Reset()
This commit is contained in:
parent
3397c93362
commit
b73cd8a5c2
@ -125,6 +125,28 @@ BitStream::~BitStream()
|
||||
free( data ); // Use realloc and free so we are more efficient than delete and new for resizing
|
||||
}
|
||||
|
||||
void BitStream::Reset( void )
|
||||
{
|
||||
// Note: Do NOT reallocate memory because BitStream is used
|
||||
// in places to serialize/deserialize a buffer. Reallocation
|
||||
// is a dangerous operation (may result in leaks).
|
||||
|
||||
if ( numberOfBitsUsed > 0 )
|
||||
{
|
||||
// memset(data, 0, BITS_TO_BYTES(numberOfBitsUsed));
|
||||
}
|
||||
|
||||
// Don't free memory here for speed efficiency
|
||||
//free(data); // Use realloc and free so we are more efficient than delete and new for resizing
|
||||
numberOfBitsUsed = 0;
|
||||
|
||||
//numberOfBitsAllocated=8;
|
||||
readOffset = 0;
|
||||
|
||||
//data=(unsigned char*)malloc(1);
|
||||
// if (numberOfBitsAllocated>0)
|
||||
// memset(data, 0, BITS_TO_BYTES(numberOfBitsAllocated));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -47,6 +47,9 @@ namespace RakNet
|
||||
/// Destructor
|
||||
~BitStream();
|
||||
|
||||
/// Resets the bitstream for reuse.
|
||||
void Reset( void );
|
||||
|
||||
/// Use this if you pass a pointer copy to the constructor
|
||||
/// *(_copyData==false) and want to overallocate to prevent
|
||||
/// *reallocation
|
||||
|
Loading…
Reference in New Issue
Block a user