diff --git a/raknet/BitStream.cpp b/raknet/BitStream.cpp index 2eade3a..4e1c8ac 100644 --- a/raknet/BitStream.cpp +++ b/raknet/BitStream.cpp @@ -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) diff --git a/raknet/BitStream.h b/raknet/BitStream.h index cf9bbe2..b5e3390 100644 --- a/raknet/BitStream.h +++ b/raknet/BitStream.h @@ -5,6 +5,7 @@ #include "Export.h" #include "NetworkTypes.h" +#include /// 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: