virtual void* allocate(size_t size, const char* typeName, const char* filename, int line) { PX_UNUSED(typeName); PX_UNUSED(filename); PX_UNUSED(line); void *ret = platformAlignedAlloc(size); return ret; }
void* PxSampleAllocator::allocate(size_t size, const char* typeName, const char* filename, int line) { if(!size) return NULL; #if defined(PX_DEBUG) || defined(PX_PROFILE) Ps::MutexT<Ps::RawAllocator>::ScopedLock lock(mMutex); // Allocate one debug block in front of each real allocation const size_t neededSize = size + sizeof(DebugBlock); void* ptr = platformAlignedAlloc(neededSize); if (NULL != ptr) { // Fill debug block DebugBlock* DB = (DebugBlock*)ptr; DB->mCheckValue = DEBUG_IDENTIFIER; DB->mSize = PxU32(size); DB->mLine = line; DB->mSlotIndex = INVALID_ID; DB->mFilename = filename; DB->mHandle = typeName ? typeName : ""; // Update global stats mTotalNbAllocs++; mNbAllocs++; mNbAllocatedBytes += PxU32(size); if(mNbAllocatedBytes>mHighWaterMark) mHighWaterMark = mNbAllocatedBytes; // Insert the allocated block in the debug memory block list if(mMemBlockList) { if(mFirstFree!=INVALID_ID) { // Recycle old location PxU32 NextFree = (PxU32)(size_t)(mMemBlockList[mFirstFree]); if(NextFree!=INVALID_ID) NextFree>>=1; mMemBlockList[mFirstFree] = ptr; DB->mSlotIndex = mFirstFree; mFirstFree = NextFree; } else { if(mMemBlockUsed==mMemBlockListSize)