| 301 | } |
| 302 | |
| 303 | forceinline void |
| 304 | MemoryManager::alloc_fill(SharedMemory& sm, size_t sz, bool first) { |
| 305 | // Adjust current heap chunk size |
| 306 | if (((requested > MemoryConfig::hcsz_inc_ratio*cur_hcsz) || |
| 307 | (sz > cur_hcsz)) && |
| 308 | (cur_hcsz < MemoryConfig::hcsz_max) && |
| 309 | !first) { |
| 310 | cur_hcsz <<= 1; |
| 311 | } |
| 312 | // Increment the size that it caters for the initial overhead |
| 313 | size_t overhead = sizeof(HeapChunk) - sizeof(double); |
| 314 | sz += overhead; |
| 315 | // Round size to next multiple of current heap chunk size |
| 316 | size_t allocate = ((sz > cur_hcsz) ? |
| 317 | (static_cast<size_t>(sz / cur_hcsz) + 1) * cur_hcsz |
| 318 | : cur_hcsz); |
| 319 | // Request a chunk of preferably size allocate, but at least size sz |
| 320 | HeapChunk* hc = sm.alloc(allocate,sz); |
| 321 | start = ptr_cast<char*>(&hc->area[0]); |
| 322 | lsz = hc->size - overhead; |
| 323 | // Link heap chunk, where the first heap chunk is kept in place |
| 324 | if (first) { |
| 325 | requested = hc->size; |
| 326 | hc->next = nullptr; cur_hc = hc; |
| 327 | } else { |
| 328 | requested += hc->size; |
| 329 | hc->next = cur_hc->next; cur_hc->next = hc; |
| 330 | } |
| 331 | #ifdef GECODE_MEMORY_CHECK |
| 332 | for (char* c = start; c < (start+lsz); c++) |
| 333 | *c = 0; |
| 334 | #endif |
| 335 | } |
| 336 | |
| 337 | forceinline |
| 338 | MemoryManager::MemoryManager(SharedMemory& sm) |