Release previously allocated memory.
| 193 | |
| 194 | // Release previously allocated memory. |
| 195 | void 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 | } |
no outgoing calls
no test coverage detected