MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / release

Method release

src/memory/PoolAllocator.cpp:195–226  ·  view source on GitHub ↗

Release previously allocated memory.

Source from the content-addressed store, hash-verified

193
194// Release previously allocated memory.
195void PoolAllocator::release(void* pointer, size_t size) {
196
197 // Lock the method with a mutex
198 std::lock_guard<std::mutex> lock(mMutex);
199
200 assert(size > 0);
201
202 // Cannot release a 0-byte allocated memory
203 if (size == 0) return;
204
205#ifndef NDEBUG
206 mNbTimesAllocateMethodCalled--;
207#endif
208
209 // If the size is larger than the maximum memory unit size
210 if (size > MAX_UNIT_SIZE) {
211
212 // Release the memory using the default deallocation
213 mBaseAllocator.release(pointer, size);
214 return;
215 }
216
217 // Get the index of the heap that has handled the corresponding allocation request
218 int indexHeap = mMapSizeToHeapIndex[size];
219 assert(indexHeap >= 0 && indexHeap < NB_HEAPS);
220
221 // Insert the released memory unit into the list of free memory units of the
222 // corresponding heap
223 MemoryUnit* releasedUnit = static_cast<MemoryUnit*>(pointer);
224 releasedUnit->nextUnit = mFreeMemoryUnits[indexHeap];
225 mFreeMemoryUnits[indexHeap] = releasedUnit;
226}

Callers 2

~PoolAllocatorMethod · 0.45
allocateMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected