| 134 | } |
| 135 | |
| 136 | PxSampleAllocator::~PxSampleAllocator() |
| 137 | { |
| 138 | #if PX_DEBUG || PX_PROFILE |
| 139 | char buffer[4096]; |
| 140 | if(mNbAllocatedBytes) |
| 141 | { |
| 142 | sprintf(buffer, "Memory leak detected: %d bytes non released\n", mNbAllocatedBytes); |
| 143 | print(buffer); |
| 144 | } |
| 145 | if(mNbAllocs) |
| 146 | { |
| 147 | sprintf(buffer, "Remaining allocs: %d\n", mNbAllocs); |
| 148 | print(buffer); |
| 149 | } |
| 150 | sprintf(buffer, "Total nb alloc: %d\n", mTotalNbAllocs); |
| 151 | print(buffer); |
| 152 | sprintf(buffer, "High water mark: %d Kb\n", mHighWaterMark/1024); |
| 153 | print(buffer); |
| 154 | |
| 155 | // Scanning for memory leaks |
| 156 | if(mMemBlockList && mNbAllocs) |
| 157 | { |
| 158 | PxU32 NbLeaks = 0; |
| 159 | sprintf(buffer, "\n\n SampleAllocator: Memory leaks detected :\n\n"); |
| 160 | print(buffer); |
| 161 | |
| 162 | for(PxU32 i=0; i<mMemBlockUsed; i++) |
| 163 | { |
| 164 | if(size_t(mMemBlockList[i])&1) |
| 165 | continue; |
| 166 | |
| 167 | const DebugBlock* DB = (const DebugBlock*)mMemBlockList[i]; |
| 168 | sprintf(buffer, " Address 0x%p, %d bytes, allocated in: %s(%d):\n\n", (void*)(DB+1), DB->mSize, DB->mFilename, DB->mLine); |
| 169 | print(buffer); |
| 170 | |
| 171 | NbLeaks++; |
| 172 | } |
| 173 | |
| 174 | sprintf(buffer, "\n Dump complete (%d leaks)\n\n", NbLeaks); |
| 175 | print(buffer); |
| 176 | } |
| 177 | // Free the Memory Block list |
| 178 | if(mMemBlockList) ::free(mMemBlockList); |
| 179 | mMemBlockList = NULL; |
| 180 | #endif |
| 181 | } |
| 182 | |
| 183 | void* PxSampleAllocator::allocate(size_t size, const char* typeName, const char* filename, int line) |
| 184 | { |