Closed wcampbell0x2a closed 1 year ago
Thanks for working on this.
I like the idea. I wonder if it we could assume types aligned by default, then certain attributes may invalidate this assumption such as bits
, reader
, ..., WDYT?
If I understand correctly, this is to avoid the un-aligned allocation path right? (We can confirm via a test in test_alloc.rs
)
I like the idea. I wonder if it we could assume types aligned by default, then certain attributes may invalidate this assumption such as
bits
,reader
, ..., WDYT?
I think this could be hard to track, as alignment in the parent struct could effect the alignment of the child struct. I added a test case in which case this causes a panic b/c of lack of alignment: https://github.com/sharksforarms/deku/pull/295/files#diff-d0c3d1ab0ac5b9134d620e8e6f9574d3f0545b36474f310912b2a85ad6ded372R37
I actually think in most cases, you would set the alignment maybe in the top-level(something I haven't implemented).
#[deku(endian = "big", aligned)]
struct DekuTest {
field_a: u8,
field_b: u8,
field_c: u16,
}
This is a draft for now, but I tested out adding an
aligned
attribute to test the performance increase.not bad
@sharksforarms I'm curious of what you think of the approach of adding an attribute and ctx for this? I acknowledge it's a bit of a foot-gun.