Why is 16 byte the recommended size for struct in C#?

后端 未结 7 524
心在旅途
心在旅途 2020-11-29 07:20

I read the Cwalina book (recommendations on development and design of .NET applications).

He says that a good designed struct has to be less than 16 bytes in size (f

7条回答
  •  情书的邮戳
    2020-11-29 07:50

    • Larger struct is not as efficient, but then.... if you HAVE more data, you have it. No sense talking about efficiency there.

    • 64 bytes should be OK.

    • The main reason possibly is copy operations.... which get IIRC slower if the struct is larger. And it must be copied around quite a lot.

    I would normally advice into using a class here ;) But without knowing the content of the struct, it is a little tricky.

提交回复
热议问题