Packed structs and alignment

Is there any good way to get a packed struct or control alignment in Mojo currently? Essentially I want the equivalent of the following Rust code, can’t seem to find a good way to do it. Searching the docs didn’t help

  1. #[repr(C, packed)]
    struct MyStruct();
    
    #[repr(align(64))]
    struct MyStruct();
    

Also packed + aligned for those of us doing networking!

I don’t think there’s a way to do this right now.

1 Like

Hi @a2svior,

Thanks for sharing this question! I confirmed with the team that this is unfortunately not possible today (but will be needed in the future!).

3 Likes

Okay, thanks for letting me know!

1 Like

I created [Feature Request] Support alignment on structs and/or struct fields · Issue #5168 · modular/modular · GitHub to track this. Should be easy.

1 Like

Many thanks! Excited about this

I’m interested in this too. I initially thought Layout handled this, but I realize Layout is for MAX’s linear algebra memory mapping.

Perhaps Layout could be separated from MAX and generalized to cover more common memory representation cases.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.