[raknet] Implement BitStream::SetNumberOfBitsAllocated()

This commit is contained in:
RD42 2024-02-12 20:33:38 +08:00
parent 56e0bf3910
commit 3397c93362
2 changed files with 14 additions and 0 deletions

View File

@ -110,6 +110,15 @@ BitStream::BitStream( char* _dataC, unsigned int lengthInBytes, bool _copyData )
data = ( unsigned char* ) _data;
}
// Use this if you pass a pointer copy to the constructor (_copyData==false) and want to overallocate to prevent reallocation
void BitStream::SetNumberOfBitsAllocated( const unsigned int lengthInBits )
{
#ifdef _DEBUG
assert( lengthInBits >= ( unsigned int ) numberOfBitsAllocated );
#endif
numberOfBitsAllocated = lengthInBits;
}
BitStream::~BitStream()
{
if ( copyData && numberOfBitsAllocated > BITSTREAM_STACK_ALLOCATION_SIZE << 3)

View File

@ -5,6 +5,7 @@
#include "Export.h"
#include "NetworkTypes.h"
#include <assert.h>
/// Arbitrary size, just picking something likely to be larger than most packets
#define BITSTREAM_STACK_ALLOCATION_SIZE 256
@ -46,6 +47,10 @@ namespace RakNet
/// Destructor
~BitStream();
/// Use this if you pass a pointer copy to the constructor
/// *(_copyData==false) and want to overallocate to prevent
/// *reallocation
void SetNumberOfBitsAllocated( const unsigned int lengthInBits );
private: