| 272 | |
| 273 | |
| 274 | void PathNodePool::Clear() |
| 275 | { |
| 276 | #ifdef TRACK_COLLISION |
| 277 | // Collision tracking code. |
| 278 | int collide=0; |
| 279 | for( unsigned i=0; i<HashSize(); ++i ) { |
| 280 | if ( hashTable[i] && (hashTable[i]->child[0] || hashTable[i]->child[1]) ) |
| 281 | ++collide; |
| 282 | } |
| 283 | //printf( "PathNodePool %d/%d collision=%d %.1f%%\n", nAllocated, HashSize(), collide, 100.0f*(float)collide/(float)HashSize() ); |
| 284 | totalCollide += collide; |
| 285 | #endif |
| 286 | |
| 287 | Block* b = blocks; |
| 288 | while( b ) { |
| 289 | Block* temp = b->nextBlock; |
| 290 | if ( b != firstBlock ) { |
| 291 | free( b ); |
| 292 | } |
| 293 | b = temp; |
| 294 | } |
| 295 | blocks = firstBlock; // Don't delete the first block (we always need at least that much memory.) |
| 296 | |
| 297 | // Set up for new allocations (but don't do work we don't need to. Reset/Clear can be called frequently.) |
| 298 | if ( nAllocated > 0 ) { |
| 299 | freeMemSentinel.next = &freeMemSentinel; |
| 300 | freeMemSentinel.prev = &freeMemSentinel; |
| 301 | |
| 302 | memset( hashTable, 0, sizeof(PathNode*)*HashSize() ); |
| 303 | for( unsigned i=0; i<allocate; ++i ) { |
| 304 | freeMemSentinel.AddBefore( &firstBlock->pathNode[i] ); |
| 305 | } |
| 306 | } |
| 307 | nAvailable = allocate; |
| 308 | nAllocated = 0; |
| 309 | cacheSize = 0; |
| 310 | } |
| 311 | |
| 312 | |
| 313 | PathNodePool::Block* PathNodePool::NewBlock() |
no test coverage detected