Does anyone know how much storage is taken when you create a reference type variable?
string
text "itemprop = "Text">
It has broken down in the following fashion:
string s = "123";
Variable: The original on the existing architecture Indicator size will be consumed (which is considered 32 bits if the OS is 32bit or the process is executed under WoW64), 32 bit or 64 bits accordingly is nested either on the stack in this case If you wanted to keep it in the array, then the pile of that place The fact is that the string is an object: 8 bytes of overhead divided 4 bytes for the table of the table indicating the actual type of object plus 4 bytes for some housekeeping bits and sink blocks. , Which allows it to be used as the target of the lock statement.
The string is always terminated by the empty character (although it is an implementation description, Im is not part of the contract), so that it can be used directly with the C-style string API, the characters are UTF-16, that is, two bytes per character. The use of the net character (description <>
) includes the following:
Pre 4.0 before.
- String length
- An integer for the length of the underlying array that holds the letters
- A character that is the first letter in the string (after which there are characters directly after it) or Empty string for empty string
string may be The bar will then consume between 16 + (2 * n) + 2 and 16 + (4 * N) + 2.
After version 4.0 of .NET > - An int for the length of the string in the letters
- A letter which is the first letter in the string (after which there are characters directly after it) or empty The empty letters for the string
String must be at least 12 + (2 * n) + 2 bytes on the heap
Note that in both cases String a bit more real world It can be taken because it uses the order of the alphabet applied to the sequence, it is possible not more than IntPtr.Size.
This string can be complicated by interning (where two different examples point to the same string, because it is irreversible) because you have divided the overhead (plus overhead) in theory Refer to 'Free' Reference for String
For more discussion about this, please note that this article is outdated for changes to 4.0.
Comments
Post a Comment