Hacker News new | ask | show | jobs
by amelius 6 days ago
No, I meant 4 bits. Assume I have only a small amount of memory, but I need to use an allocator and I don't want to use a custom allocator.

> You can't even address 4 bits.

This is not true, you can use a pointer plus extra offset data, etc.

1 comments

As I said, a slab allocator is included as part of general purpose malloc implementations. Rust is not going to be smarter here. I would bet it uses malloc underneath anyway.

Using a fat pointer to address individual bits is a waste of memory. You'd need an offset and length, and you'd have to deal with byte boundaries when accessing data. The only way I see this working is if you had a language that natively supported sub byte types and could deal with alignment of such types natively. Your best bet would be bit fields, which Rust doesn't support natively.

Dynamically allocating tiny amounts of data is a niche issue. You don't want a genetic solution to this anyway, because the efficiency will come from the constraints specific to your problem.