C # align double on 8 byte border

This is not a duplicate question.

In a modern Intel processor doubleon an 8-byte boundary built with x64, you can read and write without blocking, as it is guaranteed to be atomic. Is there a decorator or how to do this, I tell the C # compiler to align on an 8-byte border.

What is the actual code for the [Align (8)] decorator below?

public class AClass
{
    [Align(8)]
    private static double d1;
    [Align(8)]
    private static double d2
    //and so on
}
+4
source share
2 answers

You can put fields at arbitrary offsets using the [FieldOffset] attribute . Check out the example in this MSDN article, [StructLayout (LayoutKind.Explicit)] is required.

, double 8. "". , . .

x86, , , 32- , , GC, - 4. , 50% , . , , 8. , 85 000 . double [], LOH, 1000 .

x64 64- , "" > "" AnyCPU, 8. , .

+2

Windows 8- , . - , Visual # #pragma pack, , , MSVC 15.

0

Source: https://habr.com/ru/post/1606694/


All Articles