5 ms·
I was expecting this statement to be expounded: > Unfortunately this meant some of the performance wins needed to be sacrificed to avoid an increased memory fo
by ComputerGuru 3y ago
I was expecting this statement to be expounded:
> Unfortunately this meant some of the performance wins needed to be sacrificed to avoid an increased memory footprint.
- loeg 3y agoI think the idea is they might reduce the alignment in places to save memory.
- wongarsu 3y agoIn case anyone wants to try the same, my assumption is that they specified `#[repr(packed(8))]` on some structs to use alignments and paddings of at most 8 bytes. Using `[repr(align(8))]` on the field should also work, if you want more fine-grained control. https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers https://doc.rust-lang.org/reference/type-layout.html#the-ali...
- thayne 3y ago> my assumption is that they specified `#[repr(packed(8))]` on some structs to use alignments and paddings of at most 8 bytes That would mean taking a reference of any field of that struct is undefined behavior, unless the compiler does some special magic for this specific case. > Using `[repr(align(8))]` on the field I don't think you can do that directly. You would need to use a newtype that specified the alignment, and use that type for the field.
- thayne 3y agoThat would make sense, but I would like to know in which situations that happens. And can I manually reduce the alignment in a struct (say to an alignment of 8 with a struct that has other fields with alignment of 8) to reduce memory usage? Or ensure that a location uses an alignment of 16 in places I want the higher performance.