3 ms·
How would you implement the free function? You need some way to track how much memory to free.
by JoshTriplett 8y ago
How would you implement the free function? You need some way to track how much memory to free.
- CodesInChaos 8y agoBy allocating from a different block for different sizes. This means the bitmap only needs one bit per element, not per byte and reduces fragmentation. You can keep the number of blocks small by limiting the allocation sizes to a number of pre-defined buckets. From what I remember jemalloc uses bitmaps for small allocations (below the 4 KiB page size) but switches to different data structures for medium and large allocations.
- JoshTriplett 8y agoThat makes sense, yes. If you're allocating blocks of uniform size, a bitmap works just fine.