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

后端 未结 4 1516
春和景丽
春和景丽 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 05:59

    Zero.

    Unless there's gaps due to alignment, in which case it's the cost of those gaps.

    But otherwise the structure is just the same as if the fields were separate variables laid out on the stack.

    Box it though, and you're dealing with it via object which has the same overheads as any other reference type.

提交回复
热议问题