MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/PhysX / deallocate

Method deallocate

physx/samples/samplebase/SampleAllocator.cpp:262–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

260}
261
262void PxSampleAllocator::deallocate(void* memory)
263{
264 if(!memory)
265 return;
266
267#if PX_DEBUG || PX_PROFILE
268 Ps::MutexT<Ps::RawAllocator>::ScopedLock lock(mMutex);
269
270 DebugBlock* DB = ((DebugBlock*)memory)-1;
271
272 // Check we allocated it
273 if(DB->mCheckValue!=DEBUG_IDENTIFIER)
274 {
275 shdfnd::printFormatted("Error: free unknown memory!!\n");
276 // ### should we really continue??
277 return;
278 }
279
280 // Update global stats
281 mNbAllocatedBytes -= DB->mSize;
282 mNbAllocs--;
283
284 // Remove the block from the Memory block list
285 if(mMemBlockList)
286 {
287 PxU32 FreeSlot = DB->mSlotIndex;
288 assert(mMemBlockList[FreeSlot]==DB);
289
290 PxU32 NextFree = mFirstFree;
291 if(NextFree!=INVALID_ID)
292 {
293 NextFree<<=1;
294 NextFree|=1;
295 }
296
297 mMemBlockList[FreeSlot] = (void*)size_t(NextFree);
298 mFirstFree = FreeSlot;
299 }
300
301 // ### should be useless since we'll release the memory just afterwards
302 DB->mCheckValue = DEBUG_DEALLOCATED;
303 DB->mSize = 0;
304 DB->mHandle = 0;
305 DB->mFilename = NULL;
306 DB->mSlotIndex = INVALID_ID;
307 DB->mLine = INVALID_ID;
308
309 platformAlignedFree(DB);
310#else
311 platformAlignedFree(memory);
312#endif
313}
314
315static PxSampleAllocator* gAllocator = NULL;
316

Callers 2

operator deleteMethod · 0.45
operator delete[]Method · 0.45

Calls 2

printFormattedFunction · 0.85
platformAlignedFreeFunction · 0.70

Tested by

no test coverage detected