{"id":387509,"date":"2024-06-29T07:21:43","date_gmt":"2024-06-29T07:21:43","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=387509"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T07:21:43","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=387509","title":{"rendered":"<span>System.String \u043d\u0435 \u0442\u043e, \u0447\u0435\u043c \u043a\u0430\u0436\u0435\u0442\u0441\u044f. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 .NET<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0422\u0438\u043f System.String &#8212; \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u043d\u044e\u0430\u043d\u0441\u0430\u0445 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>System.String &#8212; \u044d\u0442\u043e \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u044b\u0439 \u0442\u0438\u043f;<\/p>\n<\/li>\n<li>\n<p>System.String &#8212; \u044d\u0442\u043e \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u0442\u0438\u043f. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c (\u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430). \u0412\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u0440\u043e\u0434\u0435 .Trim, .Insert \u0438 \u043f\u0440. \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0441\u0441\u044b\u043b\u0430\u043b\u0438\u0441\u044c, \u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u043e\u0432\u0443\u044e.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0433\u043b\u0443\u0431\u0436\u0435. \u041e\u043f\u0438\u0440\u0430\u044f\u0441\u044c \u043d\u0430 \u043d\u0430\u0448\u0438 \u0432\u0432\u043e\u0434\u043d\u044b\u0435, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0438 (\u043a\u0430\u043a \u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u044b) \u043d\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u0445. \u041e\u0434\u043d\u0430\u043a\u043e, \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043b\u044e\u0431\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 2Gb \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u044d\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043d\u0430 x86, \u0442\u0430\u043a \u0438 x64 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041e\u0431\u044b\u0447\u043d\u043e GC \u0437\u043d\u0430\u0435\u0442 \u043e \u0442\u043e\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0441\u0442\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u0438 \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u0430\u0445 \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f. \u041d\u043e \u044d\u0442\u043e \u043d\u0435 \u043d\u0430\u0448 \u0441\u043b\u0443\u0447\u0430\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f. \u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0435 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432 char\u2019\u043e\u043c, \u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u0445 \u0432\u043d\u0443\u0442\u0440\u0438. \u0415\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c, \u0442\u043e \u043c\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043c \u044d\u0442\u0438 \u0434\u0432\u0430 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043b\u044f.<\/p>\n<pre><code class=\"cs\">\/\/ The String class represents a static string of characters.  Many of \/\/ the string methods perform some type of transformation on the current \/\/ instance and return the result as a new string.  As with arrays, character \/\/ positions (indices) are zero-based. [Serializable] [NonVersionable] \/\/ This only applies to field layout [System.Runtime.CompilerServices.TypeForwardedFrom(\"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\")] public sealed partial class String{ \/\/ \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434  \/\/ \/\/ These fields map directly onto the fields in an EE StringObject.  See object.h for the layout. \/\/ [NonSerialize] private readonly int _stringLength;  \/\/ For empty strings, _firstChar will be '\\0', since strings are both null-terminated and length-prefixed.     \/\/ The field is also read-only, however String uses .ctors that C# doesn't recognise as .ctors,     \/\/ so trying to mark the field as 'readonly' causes the compiler to complain.     [NonSerialized]     private char _firstChar;  \/\/\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 }<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/main\/src\/libraries\/System.Private.CoreLib\/src\/System\/String.cs#L55-L61\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/a><\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 String \u0432 C# &#8212; \u044d\u0442\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 C \u0438\u043b\u0438 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u0435. \u0412 \u0444\u0430\u0439\u043b\u0435 String.cs \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f 9 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b \u043a\u0430\u043a extern \u0438 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c MethodImplAttribute \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c InternalCall. \u042d\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0435\u0439 \u0441\u0440\u0435\u0434\u043e\u0439 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043c\u0435\u0441\u0442\u0435.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043b\u0443\u0447\u0448\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0432 layout object.h \u0438 \u0443\u0432\u0438\u0434\u0438\u043c:<\/p>\n<pre><code class=\"cs\">\/*  * StringObject  *  * Special String implementation for performance.  *  *   m_StringLength - Length of string in number of WCHARs  *   m_FirstChar    - The string buffer  *  *\/ class StringObject : public Object{   \/\/ \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434      private:     DWORD   m_StringLength; WCHAR   m_FirstChar;    \/\/ \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 }<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/main\/src\/coreclr\/vm\/object.h#L863-L887\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/a><\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0442\u0441\u044f, \u0432\u043e\u0442 \u0442\u0430\u043a GC \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u0435\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/85c\/233\/a3c\/85c233a3c56fe43a77e8461601c59597.png\" alt=\"\" title=\"\" width=\"2944\" height=\"339\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/85c\/233\/a3c\/85c233a3c56fe43a77e8461601c59597.png\"\/><\/figure>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 m_StringLength \u0431\u0430\u0439\u0442 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043d\u044f\u0442\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0431\u0430\u0439\u0442\u043e\u0432, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u043c \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0438\u0445 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0438 \u0438\u0445 \u043f\u043e\u0438\u0441\u043a.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0441\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0430?<\/p>\n<blockquote>\n<p>8 (sync) + 8 (type) + 4 (length) + 4(extra field) + 2 (null terminator) + 2 * length <br \/>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f: 26 + 2 * length  <\/p>\n<\/blockquote>\n<ul>\n<li>\n<p>8 \u0431\u0430\u0439\u0442 &#8212; SyncBlock, 8 \u0431\u0430\u0439\u0442 &#8212; Method table pointer, \u0442\u0443\u0442 \u0432\u0441\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>4 \u0431\u0430\u0439\u0442 &#8212; m_stringLength member, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435<\/p>\n<\/li>\n<li>\n<p>4 \u0431\u0430\u0439\u0442 &#8212; extra field, \u0434\u043e .NET 4.0 \u044d\u0442\u043e \u043c\u0435\u0441\u0442\u043e \u0431\u044b\u043b\u043e \u043e\u0442\u0432\u0435\u0434\u0435\u043d\u043e \u0434\u043b\u044f m_arrayLength. \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u0445 \u0434\u043b\u0438\u043d\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u043c\u043e\u0433\u043b\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0434\u043b\u0438\u043d\u043d\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0432 \u043d\u0435\u0435. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u044d\u0442\u0430 \u043f\u0430\u043c\u044f\u0442\u044c \u0431\u044b\u043b\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0430 \u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0439. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u0435\u0435 \u0434\u043b\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043a\u043e\u0434\u043e\u043c pinvoke.<\/p>\n<\/li>\n<li>\n<p>2 * length &#8212; \u043f\u043e \u0434\u0432\u0430 \u0431\u0430\u0439\u0442\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 m_FirstChar. \u0421\u0442\u0440\u043e\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u0435\u044e\u0442 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443 Unicode. \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c. \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0442\u0430\u043a, \u0431\u0443\u0434\u0442\u043e \u043e\u043d\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435, \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u043e\u0439. \u041d\u0430\u0431\u043e\u0440 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 Unicode \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u043e\u043b\u0435\u0435 65536 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u0434\u0438\u043d \u0441\u0438\u043c\u0432\u043e\u043b (System.Char) \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b. \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0441\u0443\u0440\u0440\u043e\u0433\u0430\u0442\u043e\u0432, \u0433\u0434\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432\u044b\u0448\u0435 U+FFFF \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u043a\u0430\u043a \u0434\u0432\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u0430. \u041f\u043e \u0441\u0443\u0442\u0438, \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0444\u043e\u0440\u043c\u0443 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 UTF-16. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c, \u043d\u043e, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0437\u043d\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c \u0441\u0442\u043e\u0438\u0442.<\/p>\n<\/li>\n<li>\n<p>2 \u0431\u0430\u0439\u0442\u0430 &#8212; Null terminator. \u0425\u043e\u0442\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f Null (\u043d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c \u0441 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c null) \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f API, \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f Null, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0435\u0437 \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043c\u0430\u0440\u0448\u0430\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b \u043a\u0430\u043a Unicode.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 x86 \u0438 x64 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u043c\u0435\u0440\u0435 DWORD \u2013 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043f\u0430\u043c\u044f\u0442\u0438. \u0412 32-\u0431\u0438\u0442\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u043e\u043d \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 4 \u0431\u0430\u0439\u0442\u0430, \u0432 64-\u0431\u0438\u0442\u043d\u044b\u0445 \u0443\u0436\u0435 8 \u0431\u0430\u0439\u0442.<\/p>\n<p>\u041d\u043e \u043a\u0430\u043a GC \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043d \u043d\u0435 \u0437\u043d\u0430\u0435\u0442? \u041e\u0442\u0432\u0435\u0442 \u043f\u0440\u043e\u0441\u0442: \u043d\u0438\u043a\u0430\u043a. \u041e\u0431\u044b\u0447\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 GC \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c, \u0430 \u043f\u043e\u0442\u043e\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430. \u0421 String \u0432\u0441\u0435 \u0438\u043d\u0430\u0447\u0435, \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u0430 \u0441\u0430\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f String.Builder \u0438\u043b\u0438 String.Format (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 String.Builder). \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 StringBuilder.ToString(), \u043e\u043d \u0436\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 FastAllocateString \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 String:<\/p>\n<pre><code class=\"cs\">public override string ToString() {   \/\/\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434   string result = string.FastAllocateString(Length);   \/\/\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 }<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/5aa74f8bb841861120556c91bc1f583245c89831\/src\/libraries\/System.Private.CoreLib\/src\/System\/Text\/StringBuilder.cs#L322\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/a><\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0433\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435. <\/p>\n<pre><code class=\"cs\">\/\/ This class is marked EagerStaticClassConstruction because it's nice to have this \/\/ eagerly constructed to avoid the cost of defered ctors. I can't imagine any app that doesn't use string [EagerStaticClassConstruction] public partial class String {   [Intrinsic]   public static readonly string Empty = \"\";    internal static string FastAllocateString(int length)   {       \/\/ We allocate one extra char as an interop convenience so that our strings are null-       \/\/ terminated, however, we don't pass the extra +1 to the string allocation because the base       \/\/ size of this object includes the _firstChar field.       string newStr = RuntimeImports.RhNewString(EETypePtr.EETypePtrOf&lt;string>(), length);       Debug.Assert(newStr._stringLength == length);       return newStr;   } }<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/b59c6491dd9636d436ad10e087523a163fb93be0\/src\/coreclr\/nativeaot\/System.Private.CoreLib\/src\/System\/String.NativeAot.cs\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/a><\/p>\n<p>\u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0435\u0440\u0442\u043a\u0430, \u043d\u0430\u0439\u0434\u0435\u043c RhNewString:<\/p>\n<pre><code class=\"cs\">[MethodImpl(MethodImplOptions.InternalCall)] [RuntimeImport(RuntimeLibrary, \"RhNewString\")] internal static extern unsafe string RhNewString(MethodTable* pEEType, int length);  internal static unsafe string RhNewString(EETypePtr pEEType, int length)             => RhNewString(pEEType.ToPointer(), length);<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/ef15cfbbcebbfd8bcef2664bd6dad5c34ce66108\/src\/coreclr\/nativeaot\/System.Private.CoreLib\/src\/System\/Runtime\/RuntimeImports.cs#L366-L371\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/a><\/p>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0438 \u043a \u043d\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [MethodImpl(MethodImplOptions.InternalCall)], \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d CLR \u0432 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u043c \u043a\u043e\u0434\u0435. \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u043e\u0442 \u0440\u0443\u043a\u0438 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: <\/p>\n<pre><code class=\"assembly\">;; Allocate a new string. ;;  ECX == MethodTable ;;  EDX == element count FASTCALL_FUNC   RhNewString, 8          push        ecx         push        edx          ;; Make sure computing the aligned overall allocation size won't overflow         cmp         edx, MAX_STRING_LENGTH         ja          StringSizeOverflow          ; Compute overall allocation size (align(base size + (element size * elements), 4)).         lea         eax, [(edx * STRING_COMPONENT_SIZE) + (STRING_BASE_SIZE + 3)]         and         eax, -4          ; ECX == MethodTable         ; EAX == allocation size         ; EDX == scratch          INLINE_GETTHREAD    edx, ecx        ; edx = GetThread(), TRASHES ecx          ; ECX == scratch         ; EAX == allocation size         ; EDX == thread          mov         ecx, eax         add         eax, [edx + OFFSETOF__Thread__m_alloc_context__alloc_ptr]         jc          StringAllocContextOverflow         cmp         eax, [edx + OFFSETOF__Thread__m_alloc_context__alloc_limit]         ja          StringAllocContextOverflow          ; ECX == allocation size         ; EAX == new alloc ptr         ; EDX == thread          ; set the new alloc pointer         mov         [edx + OFFSETOF__Thread__m_alloc_context__alloc_ptr], eax          ; calc the new object pointer         sub         eax, ecx          pop         edx         pop         ecx          ; set the new object's MethodTable pointer and element count         mov         [eax + OFFSETOF__Object__m_pEEType], ecx         mov         [eax + OFFSETOF__String__m_Length], edx         ret<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/b2dc37ba181a7fa4427e717eab819ba3543d0ae4\/src\/coreclr\/nativeaot\/Runtime\/i386\/AllocFast.asm#L139-L187\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/a><\/p>\n<p>\u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u0435-\u0447\u0442\u043e \u0435\u0449\u0435, \u043e \u0447\u0435\u043c \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u0440\u0430\u043d\u0435\u0435. \u0410\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0439 \u0434\u043b\u0438\u043d\u044b, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>\u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0441\u0442\u0440\u043e\u043a\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c, \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 (\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0446\u0435\u043b\u043e\u043c) \u0438\u043c\u0435\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u0447\u0435\u043c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c. \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u0447\u0435\u0440\u043f\u044b\u0432\u0430\u044e\u0449\u0435\u0439, \u043d\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/727300\/\"> https:\/\/habr.com\/ru\/articles\/727300\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0422\u0438\u043f System.String &#8212; \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u0430\u043c\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u043f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e \u043d\u044e\u0430\u043d\u0441\u0430\u0445 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>System.String &#8212; \u044d\u0442\u043e \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u044b\u0439 \u0442\u0438\u043f;<\/p>\n<\/li>\n<li>\n<p>System.String &#8212; \u044d\u0442\u043e \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0439 \u0442\u0438\u043f. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u0441\u0442\u0440\u043e\u043a\u0443 \u043d\u0435\u043b\u044c\u0437\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c (\u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430). \u0412\u0441\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u0440\u043e\u0434\u0435 .Trim, .Insert \u0438 \u043f\u0440. \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0441\u0441\u044b\u043b\u0430\u043b\u0438\u0441\u044c, \u0430 \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u044e\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u043e\u0432\u0443\u044e.<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0433\u043b\u0443\u0431\u0436\u0435. \u041e\u043f\u0438\u0440\u0430\u044f\u0441\u044c \u043d\u0430 \u043d\u0430\u0448\u0438 \u0432\u0432\u043e\u0434\u043d\u044b\u0435, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u044d\u0442\u043e \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0438 (\u043a\u0430\u043a \u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u044b) \u043d\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u0445. \u041e\u0434\u043d\u0430\u043a\u043e, \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043c\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043b\u044e\u0431\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043d\u0438\u043c\u0430\u0442\u044c \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 2Gb \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u044d\u0442\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043d\u0430 x86, \u0442\u0430\u043a \u0438 x64 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041e\u0431\u044b\u0447\u043d\u043e GC \u0437\u043d\u0430\u0435\u0442 \u043e \u0442\u043e\u043c, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0441\u0442\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u0438 \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438. \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u0430\u0445 \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f. \u041d\u043e \u044d\u0442\u043e \u043d\u0435 \u043d\u0430\u0448 \u0441\u043b\u0443\u0447\u0430\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f. \u041f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0435 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432 char\u2019\u043e\u043c, \u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u0445 \u0432\u043d\u0443\u0442\u0440\u0438. \u0415\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043a \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c, \u0442\u043e \u043c\u044b \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043c \u044d\u0442\u0438 \u0434\u0432\u0430 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043b\u044f.<\/p>\n<pre><code class=\"cs\">\/\/ The String class represents a static string of characters.  Many of \/\/ the string methods perform some type of transformation on the current \/\/ instance and return the result as a new string.  As with arrays, character \/\/ positions (indices) are zero-based. [Serializable] [NonVersionable] \/\/ This only applies to field layout [System.Runtime.CompilerServices.TypeForwardedFrom(\"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\")] public sealed partial class String{ \/\/ \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434  \/\/ \/\/ These fields map directly onto the fields in an EE StringObject.  See object.h for the layout. \/\/ [NonSerialize] private readonly int _stringLength;  \/\/ For empty strings, _firstChar will be '\\0', since strings are both null-terminated and length-prefixed.     \/\/ The field is also read-only, however String uses .ctors that C# doesn't recognise as .ctors,     \/\/ so trying to mark the field as 'readonly' causes the compiler to complain.     [NonSerialized]     private char _firstChar;  \/\/\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 }<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/main\/src\/libraries\/System.Private.CoreLib\/src\/System\/String.cs#L55-L61\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/a><\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 String \u0432 C# &#8212; \u044d\u0442\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 C \u0438\u043b\u0438 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u0435. \u0412 \u0444\u0430\u0439\u043b\u0435 String.cs \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f 9 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u0435\u0447\u0435\u043d\u044b \u043a\u0430\u043a extern \u0438 \u0430\u043d\u043d\u043e\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c MethodImplAttribute \u0441 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c InternalCall. \u042d\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0435\u0439 \u0441\u0440\u0435\u0434\u043e\u0439 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043c\u0435\u0441\u0442\u0435.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043b\u0443\u0447\u0448\u0435 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u0432 layout object.h \u0438 \u0443\u0432\u0438\u0434\u0438\u043c:<\/p>\n<pre><code class=\"cs\">\/*  * StringObject  *  * Special String implementation for performance.  *  *   m_StringLength - Length of string in number of WCHARs  *   m_FirstChar    - The string buffer  *  *\/ class StringObject : public Object{   \/\/ \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434      private:     DWORD   m_StringLength; WCHAR   m_FirstChar;    \/\/ \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 }<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/main\/src\/coreclr\/vm\/object.h#L863-L887\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/a><\/p>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0442\u0441\u044f, \u0432\u043e\u0442 \u0442\u0430\u043a GC \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u0435\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 m_StringLength \u0431\u0430\u0439\u0442 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043d\u044f\u0442\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0412 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 \u0431\u0430\u0439\u0442\u043e\u0432, \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u043c \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043b\u044f \u0438\u0445 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0438 \u0438\u0445 \u043f\u043e\u0438\u0441\u043a.<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0432\u0441\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432 \u0438\u0442\u043e\u0433\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0430?<\/p>\n<blockquote>\n<p>8 (sync) + 8 (type) + 4 (length) + 4(extra field) + 2 (null terminator) + 2 * length <br \/>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f: 26 + 2 * length  <\/p>\n<\/blockquote>\n<ul>\n<li>\n<p>8 \u0431\u0430\u0439\u0442 &#8212; SyncBlock, 8 \u0431\u0430\u0439\u0442 &#8212; Method table pointer, \u0442\u0443\u0442 \u0432\u0441\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e.<\/p>\n<\/li>\n<li>\n<p>4 \u0431\u0430\u0439\u0442 &#8212; m_stringLength member, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435<\/p>\n<\/li>\n<li>\n<p>4 \u0431\u0430\u0439\u0442 &#8212; extra field, \u0434\u043e .NET 4.0 \u044d\u0442\u043e \u043c\u0435\u0441\u0442\u043e \u0431\u044b\u043b\u043e \u043e\u0442\u0432\u0435\u0434\u0435\u043d\u043e \u0434\u043b\u044f m_arrayLength. \u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u0445 \u0434\u043b\u0438\u043d\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 \u043c\u043e\u0433\u043b\u0430 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0434\u043b\u0438\u043d\u043d\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432, \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0432 \u043d\u0435\u0435. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u044f\u0445 \u044d\u0442\u0430 \u043f\u0430\u043c\u044f\u0442\u044c \u0431\u044b\u043b\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0430 \u0438 \u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043f\u0443\u0441\u0442\u043e\u0439. \u0412\u0435\u0440\u043e\u044f\u0442\u043d\u0435\u0435 \u0434\u043b\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043a\u043e\u0434\u043e\u043c pinvoke.<\/p>\n<\/li>\n<li>\n<p>2 * length &#8212; \u043f\u043e \u0434\u0432\u0430 \u0431\u0430\u0439\u0442\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 m_FirstChar. \u0421\u0442\u0440\u043e\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u0435\u044e\u0442 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443 Unicode. \u042d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u0437\u043d\u0430\u0442\u044c \u0438 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c. \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0442\u0430\u043a, \u0431\u0443\u0434\u0442\u043e \u043e\u043d\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0435, \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u043e\u0439. \u041d\u0430\u0431\u043e\u0440 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 Unicode \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0431\u043e\u043b\u0435\u0435 65536 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u0434\u0438\u043d \u0441\u0438\u043c\u0432\u043e\u043b (System.Char) \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b. \u042d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0441\u0443\u0440\u0440\u043e\u0433\u0430\u0442\u043e\u0432, \u0433\u0434\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432\u044b\u0448\u0435 U+FFFF \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0432 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 \u043a\u0430\u043a \u0434\u0432\u0430 \u0441\u0438\u043c\u0432\u043e\u043b\u0430. \u041f\u043e \u0441\u0443\u0442\u0438, \u0441\u0442\u0440\u043e\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0444\u043e\u0440\u043c\u0443 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 UTF-16. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0443 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c, \u043d\u043e, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435, \u0437\u043d\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c \u0441\u0442\u043e\u0438\u0442.<\/p>\n<\/li>\n<li>\n<p>2 \u0431\u0430\u0439\u0442\u0430 &#8212; Null terminator. \u0425\u043e\u0442\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f Null (\u043d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c \u0441 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c null) \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f API, \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f Null, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0435\u0437 \u043a\u0430\u043a\u043e\u0433\u043e-\u043b\u0438\u0431\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043c\u0430\u0440\u0448\u0430\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b \u043a\u0430\u043a Unicode.<\/p>\n<\/li>\n<\/ul>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 x86 \u0438 x64 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c\u0438 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0430\u0437\u043c\u0435\u0440\u0435 DWORD \u2013 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043f\u0430\u043c\u044f\u0442\u0438. \u0412 32-\u0431\u0438\u0442\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u043e\u043d \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 4 \u0431\u0430\u0439\u0442\u0430, \u0432 64-\u0431\u0438\u0442\u043d\u044b\u0445 \u0443\u0436\u0435 8 \u0431\u0430\u0439\u0442.<\/p>\n<p>\u041d\u043e \u043a\u0430\u043a GC \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043d \u043d\u0435 \u0437\u043d\u0430\u0435\u0442? \u041e\u0442\u0432\u0435\u0442 \u043f\u0440\u043e\u0441\u0442: \u043d\u0438\u043a\u0430\u043a. \u041e\u0431\u044b\u0447\u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 GC \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c, \u0430 \u043f\u043e\u0442\u043e\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043a\u043b\u0430\u0441\u0441\u0430. \u0421 String \u0432\u0441\u0435 \u0438\u043d\u0430\u0447\u0435, \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0438\u043f\u0430 \u0441\u0430\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f String.Builder \u0438\u043b\u0438 String.Format (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 String.Builder). \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 StringBuilder.ToString(), \u043e\u043d \u0436\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 FastAllocateString \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430 String:<\/p>\n<pre><code class=\"cs\">public override string ToString() {   \/\/\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434   string result = string.FastAllocateString(Length);   \/\/\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 }<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/5aa74f8bb841861120556c91bc1f583245c89831\/src\/libraries\/System.Private.CoreLib\/src\/System\/Text\/StringBuilder.cs#L322\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/a><\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0433\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435. <\/p>\n<pre><code class=\"cs\">\/\/ This class is marked EagerStaticClassConstruction because it's nice to have this \/\/ eagerly constructed to avoid the cost of defered ctors. I can't imagine any app that doesn't use string [EagerStaticClassConstruction] public partial class String {   [Intrinsic]   public static readonly string Empty = \"\";    internal static string FastAllocateString(int length)   {       \/\/ We allocate one extra char as an interop convenience so that our strings are null-       \/\/ terminated, however, we don't pass the extra +1 to the string allocation because the base       \/\/ size of this object includes the _firstChar field.       string newStr = RuntimeImports.RhNewString(EETypePtr.EETypePtrOf&lt;string>(), length);       Debug.Assert(newStr._stringLength == length);       return newStr;   } }<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/b59c6491dd9636d436ad10e087523a163fb93be0\/src\/coreclr\/nativeaot\/System.Private.CoreLib\/src\/System\/String.NativeAot.cs\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/a><\/p>\n<p>\u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0435\u0440\u0442\u043a\u0430, \u043d\u0430\u0439\u0434\u0435\u043c RhNewString:<\/p>\n<pre><code class=\"cs\">[MethodImpl(MethodImplOptions.InternalCall)] [RuntimeImport(RuntimeLibrary, \"RhNewString\")] internal static extern unsafe string RhNewString(MethodTable* pEEType, int length);  internal static unsafe string RhNewString(EETypePtr pEEType, int length)             => RhNewString(pEEType.ToPointer(), length);<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/ef15cfbbcebbfd8bcef2664bd6dad5c34ce66108\/src\/coreclr\/nativeaot\/System.Private.CoreLib\/src\/System\/Runtime\/RuntimeImports.cs#L366-L371\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/a><\/p>\n<p>\u042d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u043a\u0430\u043a \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0438 \u043a \u043d\u0435\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d \u0430\u0442\u0440\u0438\u0431\u0443\u0442 [MethodImpl(MethodImplOptions.InternalCall)], \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d CLR \u0432 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u043c \u043a\u043e\u0434\u0435. \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0441\u0442\u0435\u043a \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u043e\u0442 \u0440\u0443\u043a\u0438 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438: <\/p>\n<pre><code class=\"assembly\">;; Allocate a new string. ;;  ECX == MethodTable ;;  EDX == element count FASTCALL_FUNC   RhNewString, 8          push        ecx         push        edx          ;; Make sure computing the aligned overall allocation size won't overflow         cmp         edx, MAX_STRING_LENGTH         ja          StringSizeOverflow          ; Compute overall allocation size (align(base size + (element size * elements), 4)).         lea         eax, [(edx * STRING_COMPONENT_SIZE) + (STRING_BASE_SIZE + 3)]         and         eax, -4          ; ECX == MethodTable         ; EAX == allocation size         ; EDX == scratch          INLINE_GETTHREAD    edx, ecx        ; edx = GetThread(), TRASHES ecx          ; ECX == scratch         ; EAX == allocation size         ; EDX == thread          mov         ecx, eax         add         eax, [edx + OFFSETOF__Thread__m_alloc_context__alloc_ptr]         jc          StringAllocContextOverflow         cmp         eax, [edx + OFFSETOF__Thread__m_alloc_context__alloc_limit]         ja          StringAllocContextOverflow          ; ECX == allocation size         ; EAX == new alloc ptr         ; EDX == thread          ; set the new alloc pointer         mov         [edx + OFFSETOF__Thread__m_alloc_context__alloc_ptr], eax          ; calc the new object pointer         sub         eax, ecx          pop         edx         pop         ecx          ; set the new object's MethodTable pointer and element count         mov         [eax + OFFSETOF__Object__m_pEEType], ecx         mov         [eax + OFFSETOF__String__m_Length], edx         ret<\/code><\/pre>\n<p><a href=\"https:\/\/github.com\/dotnet\/runtime\/blob\/b2dc37ba181a7fa4427e717eab819ba3543d0ae4\/src\/coreclr\/nativeaot\/Runtime\/i386\/AllocFast.asm#L139-L187\" rel=\"noopener noreferrer nofollow\">\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043a\u043e\u0434.<\/a><\/p>\n<p>\u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u0435-\u0447\u0442\u043e \u0435\u0449\u0435, \u043e \u0447\u0435\u043c \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u0440\u0430\u043d\u0435\u0435. \u0410\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0443\u044e \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u0439 \u0434\u043b\u0438\u043d\u044b, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>\u0421 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0441\u0442\u0440\u043e\u043a\u0438 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0444\u0443\u043d\u0434\u0430\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c, \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u044b. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0441\u0442\u0440\u043e\u043a\u0438 (\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0446\u0435\u043b\u043e\u043c) \u0438\u043c\u0435\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c, \u0447\u0435\u043c \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c. \u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u043d\u0430\u044f \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u0447\u0435\u0440\u043f\u044b\u0432\u0430\u044e\u0449\u0435\u0439, \u043d\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b, \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c \u0432\u0430\u0448\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u0432.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/727300\/\"> https:\/\/habr.com\/ru\/articles\/727300\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-387509","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/387509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=387509"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/387509\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=387509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=387509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=387509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}