hawkw / sharded-slab

a lock-free concurrent slab (experimental)
MIT License
269 stars 17 forks source link

make index type `NonZeroUsize` #42

Open GallagherCommaJack opened 4 years ago

GallagherCommaJack commented 4 years ago

It'd be nice to be able to have an Option<Key> which didn't take up more space than Key in memory.

hawkw commented 4 years ago

We could do this — it might be useful for the tracing-subscriber use-case, as well, where we're currently adding 1 to all indices because 0 is reserved.

However, 0 is a valid slab index. If we did this, we would either end up wasting one slot on thread 0's slab, or need to do some munging of indices ourselves to avoid that. This may be worth it, however.

inanna-malick commented 4 years ago

Would it be reasonable to add an associated Key type to the Config trait, with the default being usize to allow for custom configs that use std::num::NonZeroUsize instead?

hawkw commented 4 years ago

@inanna-malick hmm, in theory, that could work! Could be worth experimenting with.

inanna-malick commented 4 years ago

I have a sketch of what it might look like here - it's not quite complete (I don't quite understand everything that's going on around key generation & what would be required to skip 0 there) but it shows the approximate scope of the changes https://github.com/inanna-malick/sharded-slab/tree/associated-key-type