42 uint8_t* mCapacityEnd;
45 MemoryBuffer(
const TAllocator& inAlloc = TAllocator() ) : TAllocator( inAlloc ), mBegin( 0 ), mEnd( 0 ), mCapacityEnd( 0 ) {}
48 if ( mBegin ) TAllocator::deallocate( mBegin );
50 uint32_t size()
const {
return static_cast<uint32_t
>( mEnd - mBegin ); }
51 uint32_t capacity()
const {
return static_cast<uint32_t
>( mCapacityEnd - mBegin ); }
52 uint8_t* begin() {
return mBegin; }
53 uint8_t* end() {
return mEnd; }
54 void setEnd(uint8_t* nEnd) { mEnd = nEnd; }
55 const uint8_t* begin()
const {
return mBegin; }
56 const uint8_t* end()
const {
return mEnd; }
57 void clear() { mEnd = mBegin; }
58 uint32_t write( uint8_t inValue )
66 template<
typename TDataType>
67 uint32_t write(
const TDataType& inValue )
69 uint32_t writtenSize =
sizeof(TDataType);
71 const uint8_t* __restrict readPtr =
reinterpret_cast< const uint8_t*
>( &inValue );
72 uint8_t* __restrict writePtr = mEnd;
73 for ( uint32_t idx = 0; idx <
sizeof(TDataType); ++idx ) writePtr[idx] = readPtr[idx];
78 template<
typename TDataType>
79 uint32_t write(
const TDataType* inValue, uint32_t inLength )
81 if ( inValue && inLength )
83 uint32_t writeSize = inLength *
sizeof( TDataType );
85 PxMemCopy( mBegin + size(), inValue, writeSize );
94 template<
typename TDataType>
95 uint32_t write(
const TDataType* inValue, uint32_t inLength, int32_t index)
97 if (inValue && inLength)
99 uint32_t writeSize = inLength *
sizeof(TDataType);
100 PX_ASSERT(mBegin + index + writeSize < mCapacityEnd);
101 PxMemCopy(mBegin + index, inValue, writeSize);
107 void growBuf( uint32_t inAmount )
109 uint32_t newSize = size() + inAmount;
112 void resize( uint32_t inAmount )
115 mEnd = mBegin + inAmount;
117 void reserve( uint32_t newSize )
119 uint32_t currentSize = size();
120 if ( newSize >= capacity() )
122 const uint32_t allocSize = mBegin ? newSize * 2 : newSize;
124 uint8_t* newData =
static_cast<uint8_t*
>(TAllocator::allocate(allocSize, __FILE__, __LINE__));
125 memset(newData, 0xf,allocSize);
128 PxMemCopy( newData, mBegin, currentSize );
129 TAllocator::deallocate( mBegin );
132 mEnd = mBegin + currentSize;
133 mCapacityEnd = mBegin + allocSize;
143 uint8_t* mCapacityEnd;
146 TempMemoryBuffer(uint8_t* data, int32_t size) : mBegin(data), mEnd(data), mCapacityEnd(data + size) {}
150 uint32_t size()
const {
return static_cast<uint32_t
>(mEnd - mBegin); }
151 uint32_t capacity()
const {
return static_cast<uint32_t
>(mCapacityEnd - mBegin); }
152 const uint8_t* begin() {
return mBegin; }
153 uint8_t* end() {
return mEnd; }
154 const uint8_t* begin()
const {
return mBegin; }
155 const uint8_t* end()
const {
return mEnd; }
156 uint32_t write(uint8_t inValue)
163 template<
typename TDataType>
164 uint32_t write(
const TDataType& inValue)
166 uint32_t writtenSize =
sizeof(TDataType);
167 const uint8_t* __restrict readPtr =
reinterpret_cast<const uint8_t*
>(&inValue);
168 uint8_t* __restrict writePtr = mEnd;
169 for (uint32_t idx = 0; idx <
sizeof(TDataType); ++idx) writePtr[idx] = readPtr[idx];
174 template<
typename TDataType>
175 uint32_t write(
const TDataType* inValue, uint32_t inLength)
177 if (inValue && inLength)
179 uint32_t writeSize = inLength *
sizeof(TDataType);
180 PxMemCopy(mBegin + size(), inValue, writeSize);
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_FORCE_INLINE void * PxMemCopy(void *dest, const void *src, PxU32 count)
Copies the bytes of one memory block to another. The memory blocks must not overlap.
Definition PxMemory.h:83