F # and very low-level performance optimization are not best friends, but then ... some smart people do magic even with Java, which has no value types and no real shared collections for them.
1) Recently, I am a big fan of flies. If you allow it, you can wrap an array of bytes and access the elements of the structure using offsets. C # example here . SBE / FlatBuffers even have tools to automatically create wrappers from definitions.
2) If you can stay in an unsafe context in C # to do the job, casting pointers is very simple and efficient. However, for this you need to bind an array of bytes and save its descriptor for subsequent release, or remain within a fixed keyword. If you have many small ones without a pool, you may have problems with the GC.
3) The third option is to abuse a system like .NET and use an array of bytes with IL like this (this can be encoded in F # if you insist :)):
static T UnsafeCast(object value) { ldarg.1
I tried this option and even had a snippet somewhere if you needed, but this approach is inconvenient for me because I do not understand its consequences for the GC. We have two objects supported by the same memory, what happens when one of them is GCed? I was going to ask a new question about this detail, will publish it soon.
The latter approach may be useful for arrays of structures, but for one structure it will close it or copy it anyway. Since the structures are on the stack and passed by value, you will probably get better results by simply hovering over byte[] in unsafe C # or using Marshal.PtrToStructure , as in the other answer here, and then copy by value. Copying is not the worst, especially on the stack, but allocating new objects and the GC is the enemy, so you need byte arrays, and this will add a lot more to the overall performance than the custom structure problem.
But if your structure is very large , option 1 could still be better.