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

后端 未结 7 473
心在旅途
心在旅途 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:37

    I think another key point is that if you have a list with a million structs, that is still only one memory allocation on the heap, while a list with a million classes in it is going to have about a million separate heap objects. The garbage collection load is something quite different in both cases. From this point of view, the struct may come out ahead.

提交回复
热议问题