logoalt Hacker News

tialaramex • yesterday at 1:19 PM • 1 reply • view on HN

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.


Replies

ozgrakkurt • yesterday at 3:05 PM

The way I use it is to have a more long lived bump allocator and a "temporary" bump allotor which I regularly roll back to some earlier offset.

If a function doesn't know the size it needs for a vector for example. It will at least have an upper bound, then it can allocate with the upper bound on the temporary alloc and construct the thing. After it is constructed it gets moved to the more long lived allocator. So the program is really only accessing three sections of memory at a time including the stack. Allocation/deallocation are just integer increment/decrement. And I can put an upper bound on the amount of memory a section of the program will use.

This way you don't need the SSO types at all.

➕ show 1 reply