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

add SizeOfInstanceFields for Unsafe #33

Open
dzmitry-lahoda opened this issue Feb 11, 2021 · 4 comments
Open

add SizeOfInstanceFields for Unsafe #33

dzmitry-lahoda opened this issue Feb 11, 2021 · 4 comments

Comments

@dzmitry-lahoda
Copy link
Contributor

SizeOf != SizeOfInstance Fields. needed for networking.

@SergeyTeplyakov
Copy link
Owner

Could you please clarify the issue a bit more?

@dzmitry-lahoda
Copy link
Contributor Author

dzmitry-lahoda commented Feb 11, 2021

What is size of this struct, 5 or 8?

    [StructLayout(LayoutKind.Explicit)]
    public struct ChallengeRequest
    {
        public static ChallengeRequest Create()
        {
            return new ChallengeRequest();
        }

        [FieldOffset(0)]
        public RequestMessageType Type;

        /// <summary>
        /// 0 (using a u32 here since that pads the request to the same size as theresponse)
        /// </summary>
        [FieldOffset(1)]
        public uint Padding;
    }

C# sizeof and Unsafe.SizeOf will tell 8, but I want 5. And not using reflection or runtime codegen.

@SergeyTeplyakov
Copy link
Owner

Ok. Now I get it. Thanks. Will fix.

@dzmitry-lahoda
Copy link
Contributor Author

I am not sure if reflection based stuff have or not have that type of API, but unsafe based stuff (which works within AOT), do not have that for sure. But anyway, because it lacked in unsafe part, calculated manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants