What is the memory overhead of a .NET custom struct type?

后端 未结 4 1461
春和景丽
春和景丽 2021-02-20 05:27

There is a fixed overhead associated with a .NET object as more fully outlined in this SO question: What is the memory overhead of a .NET Object being 12 or 24 bytes depending o

4条回答
  •  忘了有多久
    2021-02-20 06:20

    You may have some overhead with fields' alignments:

    https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.structlayoutattribute(v=vs.100).aspx

    E.g.

      public struct Test {
        public Byte A;
        public long B;
      }
    

    will be of size 16 bytes on 64-bit process and 12 bytes on 32-bit process correspondingly (when we could expect 9 bytes only);

提交回复
热议问题