#allocating arbitrary bit sizes
1 messages · Page 1 of 1 (latest)
it'll allocate 10 times @sizeOf(u7), so 10 bytes on all sane hardware
so it will allocate the same amount as alloc(u8,10)?
yes
so if i alloc(u4,10) that will also be 10 bytes?
yup
that is a bit unfortunate, but i suppose it make sense.
the elements of the returned slice must each reside in its own unique address, so each takes up one byte
you can, however, use packed struct to create bit-packed aggregate data on your own
So i would theoretically need to allocate 5 u8 and bit shift to get 10 u4?
or this packed struct you speak of
yes. you can allocate 5 u8s, or 5 packed struct { a: u4, b: u4 } to compress the data down - but that won't be done automatically for you
std.bit_set though?
who is this bit_set you speak of?
it's this - but last I checked it's not generic over the element, only working with booleans
essentially a bit-packed version of std.ArrayListUnmanaged(bool)