Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic structure alignment by IntPtr.Size #61107

Closed
NN--- opened this issue Nov 2, 2021 · 2 comments
Closed

Dynamic structure alignment by IntPtr.Size #61107

NN--- opened this issue Nov 2, 2021 · 2 comments
Labels
untriaged New issue has not been triaged by the area owner

Comments

@NN---
Copy link
Contributor

NN--- commented Nov 2, 2021

There are use cases where structure has different alignment in 32 and 64 bits.
It would be very useful to be able to align structure by size of pointer or its derivative.

[StructLayout(LayoutKind.Sequential, Pack = IntPtr.Size)]
struct MyStruct
{
   public int I;
}

A possible solution mentioned in #33899 is to use two structures and introduce an interface.
However it means boxing and requires defining properties instead of simple fields.
Much more convenient solution is to allow packing depending on IntPtr.Size.

P.S.
It would be also nice to allow IntPtr.Size usage in arrays marshaling:

[StructLayout(LayoutKind.Sequential, Pack = IntPtr.Size)]
public value struct typeData
{
   [MarshalAs(UnmanagedType.ByValArray, SizeConst = IntPtr.Size)] byte[] a1;
}
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Nov 2, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@jkotas
Copy link
Member

jkotas commented Nov 2, 2021

Duplicate of #60573

@jkotas jkotas marked this as a duplicate of #60573 Nov 2, 2021
@jkotas jkotas closed this as completed Nov 2, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

2 participants