Fixed-sized buffers in C# are only syntactic sugar; it doesn't enable anything you can do yourself. You can simmulate what C# is doing by:

1. Use the explicit struct layout for the struct, specifying the size of the struct. E.g.,

1
[StructLayout(LayoutKind.Explicit, Size=8)]

2. Put FieldOffset attributes on all your fields with correctly calculated field offsets.

1
[FieldOffset(0)] int a;

3. Optionally provide a way to access the field in a more managed-code-friendly way. What you want to do here often depends on how managed clients typically use the struct. E.g.

1
2
3
int GetElement(int i) {
    return Marshal.ReadInt32(&a, i);
}
By on 1/15/2009 6:47 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper