| 485 | fl::size mTotalDeallocated; |
| 486 | |
| 487 | Slab* createSlab() FL_NOEXCEPT { |
| 488 | Slab* slab = static_cast<Slab*>(Malloc(sizeof(Slab))); |
| 489 | if (!slab) { |
| 490 | return nullptr; |
| 491 | } |
| 492 | |
| 493 | // Use placement new to properly initialize the Slab |
| 494 | new(slab) Slab(); |
| 495 | |
| 496 | slab->memory = static_cast<u8*>(Malloc(SLAB_MEMORY_SIZE)); |
| 497 | if (!slab->memory) { |
| 498 | slab->~Slab(); |
| 499 | Free(slab); |
| 500 | return nullptr; |
| 501 | } |
| 502 | |
| 503 | // Initialize all blocks in the slab as free |
| 504 | slab->allocated_blocks.reset(); // All blocks start as free |
| 505 | |
| 506 | // Add slab to the slab list |
| 507 | slab->next = mSlabs; |
| 508 | mSlabs = slab; |
| 509 | |
| 510 | return slab; |
| 511 | } |
| 512 | |
| 513 | void* allocateFromSlab(fl::size n = 1) FL_NOEXCEPT { |
| 514 | // Try to find n contiguous free blocks in existing slabs |