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

前端 未结 6 1376
独厮守ぢ
独厮守ぢ 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:35

    The size figure comes largely from the amount of time it takes to copy the struct on the stack, for example to pass to a method. Anything much larger than this and you are consuming a lot of stack space and CPU cycles just copying data - when a reference to an immutable class (even with dereferencing) could be a lot more efficient.

提交回复
热议问题