Why should a .NET struct be less than 16 bytes?

前端 未结 6 1359
独厮守ぢ
独厮守ぢ 2020-11-30 07:35

I\'ve read in a few places now that the maximum instance size for a struct should be 16 bytes.

But I cannot see where that number (16) comes from.

Browsing a

6条回答
  •  再見小時候
    2020-11-30 07:56

    I think the 16 bytes is just a rule of thumb from a performance point of view. An object in .NET uses at least 24 bytes of memory (IIRC), so if you made your structure much larger than that, a reference type would be preferable.

    I can't think of any reason why they chose 16 bytes specifically.

提交回复
热议问题