There is an old article talking about some string internals in .NET/C#. One of the interesting tidbits:
m_stringLength
This is the logical length of the string, the one returned by String.Length. Because a number of high bits are used for additional flags to enhance performance, the maximum length of the string is constrained to a limit much smaller than UInt32.Max for 32bit systems. Some of these flags indicate the string contains simple characters such as plain ASCII and will not required invoking complex UNICODE algorithms for sorting and comparison tests.
I know that BinaryReader does read strings as length-prefixed with 7bit-encoded integer, does that mean the extra space is used for the aforementioned string flag (0 - ASCII, 1 - wide)?
Is this relevant for mono starting from version 2.0 and above? I'm writing a simple custom wrapper around a string to make it mutable and although that string is not gonna be used in sorting or comparisons (for now) - I was wondering if I should allocate new string pre-emptively filled with ASCII or UNICODE (i.e. if I know/assume the content) char so the flag will be set by default.