logoalt Hacker News

ozgrakkurt • yesterday at 11:25 AM • 1 reply • view on HN

This is a bit of a misunderstanding. Using a bump allocator is also useful for avoiding things like SmallVec. It can also good for reducing page faults or using the CPU cache better.

It has a lot of applications but people just don't use it for those applications.

It is just difficult to understand why people use it unless you actually understand what effects it has. I think a lot of people are making the mistake of assuming they would have realized the need for it naturally, but it is pretty hard to just stumble into it as an idea.

I understood the importance because of writing storage engines in rust for some years where I had a lot of trouble avoiding memory fragmentation with global allocators and also having page faults destroying performance. Even then you don't immediately think "oh I should use a bump allocator", you would still need to understand how the design of that allocator effects the problems you have.


Replies

tialaramex • yesterday at 1:19 PM

A SmallVec and the SSO types I've spent more time thinking about seem like poor use cases for an Allocator mechanism.

After some thought, the best use case I could come up with was as follows: a set of K growable arrays such that in total they have M entries but each might have N = 0..=M entries of its own and so with SmallVec that needs K*M space but with an Allocator you're sure it all fits in M space which may be a significant improvement.

Except I think the correct representation for that is a single Boxed array or similar and K slices of that Boxed array instead.

➕ show 1 reply