.NET: What is the maximum recommended value type size?

What is the maximum recommended value type size? I think I read that Microsoft assumes that they do not exceed 16 bytes, but I can not find the link.

+5
source share
3 answers

I found a discussion and a free recommendation on MSDN, "Using Classes and Structures in Visual Basic.NET" :

If your application makes a large number of copies of a variable, the memory required for this variable may be a factor in determining whether it should be a value type or a reference type. There is a trade-off between copying all bytes of the value type, rather than allocating a new reference type on the heap. The more copies of the variable used by your application, the more important this difference.

Theoretical observation can serve as a reference point. Suppose you are writing a test application that does the following:

[..]

Depending on the execution and loading platform from other tasks, you are likely to observe the following:

  • If the total data size is less than 16 bytes, the copy cycle of the structure instance may be slightly faster than the copy cycle of the class instance.
  • 16 , .
  • 16 , , , .

, - :

, :

  • , (, ..).
  • 16 .
  • .
  • .
+2

, Microsoft , struct 16 .

:

+4

17 , 16 ; Microsoft , 16 . , , , .

, , , . , , (, ..) ​​ . , , , ; ( 32/64- ) . .

, , , , , , . . , . , , , . , .

If one structure contains one code to minimize the number of copies that can be copied, even large structures can be quite efficient. Although 17-byte structures are slower than 16-byte structures, a mutable 100-byte structure can be more efficient than an equivalent immutable class.

0
source

All Articles