typedef struct intset { uint32_t encoding; uint32_t length; int8_t contents[]; } intset;
we know encoding only three define, can set to uint8_t ?
Comment From: lindianyin
Because of memory alignment?
Comment From: trevor211
To fit into the 64 byte arena of jemalloc?
Comment From: oranagra
indeed. changing the type of encoding to one byte won't change a thing.
the compiler will add 3 bytes of padding before the next member since it must be 4 bytes aligned.
and even if we changed the order to put the length first, (and let's ignore the reserved array at the end of the struct for a moment) the compiler will need to add padding to the end of the struct in order to make it possible to use in an array (which we don't use).
we can add packed attribute to avoid that, but then if the contents is actually an array of anything other than one byte, it would cause unaligned memory access.
and also the saving won't help much due to allocator bins masking many cases causing internal fragmentation instead of real savings.
in theory we can use different header structs for different intset types, and have some rare wins (especially when the encoding is for one byte items), but i don't think it justifies the added code.