{"id":287359,"date":"2018-08-16T14:07:32","date_gmt":"2018-08-16T10:07:32","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=287359"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=287359","title":{"rendered":"[DotNetBook] Span, Memory \u0438 ReadOnlyMemory"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/420051\/\" class=\"post__text post__text-html js-mediator-article\">\n<p><img decoding=\"async\" width=\"350\" src=\"https:\/\/habrastorage.org\/webt\/34\/ua\/e6\/34uae6usmglyw10vxga3sgfgh8c.jpeg\" align=\"left\"> \u042d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0446\u0435\u043b\u0443\u044e \u0441\u0435\u0440\u0438\u044e \u0441\u0442\u0430\u0442\u0435\u0439, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043a\u043d\u0438\u0433\u0430 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 .NET CLR, \u0438 .NET \u0432 \u0446\u0435\u043b\u043e\u043c. \u0417\u0430 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043a\u0430\u0442.<\/p>\n<p>  <\/p>\n<h2 id=\"memorylttgt-i-readonlymemorylttgt\">Memory&lt;T&gt; \u0438 ReadOnlyMemory&lt;T&gt;<\/h2>\n<p>  <\/p>\n<p>\u0412\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0442\u043b\u0438\u0447\u0438\u0439 <code>Memory&lt;T&gt;<\/code> \u043e\u0442 <code>Span&lt;T&gt;<\/code> \u0434\u0432\u0430. \u041f\u0435\u0440\u0432\u043e\u0435 \u2014 \u0442\u0438\u043f <code>Memory&lt;T&gt;<\/code> \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f <code>ref<\/code> \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0442\u0438\u043f\u0430. \u0422.\u0435., \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0442\u0438\u043f <code>Memory&lt;T&gt;<\/code> \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0442\u0435\u043a\u0435, \u044f\u0432\u043b\u044f\u044f\u0441\u044c \u043b\u0438\u0431\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043b\u0438\u0431\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0430 \u043b\u0438\u0431\u043e \u0435\u0433\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u043d\u043e \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043a\u0443\u0447\u0435, \u0441\u0441\u044b\u043b\u0430\u044f\u0441\u044c \u043e\u0442\u0442\u0443\u0434\u0430 \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0430 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u0443\u044e \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0432 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 <code>Memory&lt;T&gt;<\/code> \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 <code>Span&lt;T&gt;<\/code>. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 <code>Span&lt;T&gt;<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 <em>\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/em> \u043d\u0435\u043a\u0438\u043c \u0431\u0443\u0444\u0435\u0440\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0442\u0438\u043f <code>Memory&lt;T&gt;<\/code> \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f <em>\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f<\/em> \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0431\u0443\u0444\u0435\u0440\u0435, \u0430 \u043d\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c.<\/p>\n<p>  <\/p>\n<blockquote><p>\u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u2014 \u0432\u0442\u043e\u0440\u0430\u044f \u0438\u0437 \u0446\u0438\u043a\u043b\u0430 \u043f\u0440\u043e Span&lt;T&gt; \u0438 Memory&lt;T&gt;. \u041e\u043d\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0432\u043e\u0434\u043d\u043e\u0439 \u0434\u043b\u044f Memory&lt;T&gt; \u0432 \u0442\u043e\u043c \u043f\u043b\u0430\u043d\u0435 \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u044f \u0440\u0435\u0448\u0438\u043b \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0449\u0443\u044e \u0442\u0435\u0440\u043c\u0438\u043d\u0438\u043b\u043e\u0433\u0438\u044e, \u0430 \u0432\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u0440\u0435\u0448\u0438\u043b \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e  <\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/post\/418911\/\">Span&lt;T&gt;: \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 .NET<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/post\/420051\/\">Span&lt;T&gt; Memory&lt;T&gt; \u0438 ReadOnlyMemory&lt;T&gt;<\/a> (\u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f)<\/li>\n<li>\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Span&lt;T&gt; \u0438 Memory&lt;T&gt;<\/li>\n<\/ul>\n<p>  <\/p><\/blockquote>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u041e\u0442\u0441\u044e\u0434\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0432 API:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>Memory&lt;T&gt;<\/code> \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043e\u043d \u0437\u0430\u0432\u0435\u0434\u0443\u0435\u0442. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043e\u043d \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>Span<\/code> \u0438 \u043c\u0435\u0442\u043e\u0434 <code>Slice<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u0440\u0430\u0431\u043e\u0447\u0443\u044e \u043b\u043e\u0448\u0430\u0434\u043a\u0443 \u2014 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0442\u0438\u043f\u0430 <code>Span<\/code>.<\/li>\n<li><code>Memory&lt;T&gt;<\/code> \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u0435\u0442\u043e\u0434 <code>Pin()<\/code>, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u0434\u043b\u044f \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0435\u0432, \u043a\u043e\u0433\u0434\u0430 \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0439\u0441\u044f \u0431\u0443\u0444\u0435\u0440 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 <code>unsafe<\/code> \u043a\u043e\u0434. \u041f\u0440\u0438 \u0435\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0435 \u0434\u043b\u044f \u0441\u043b\u0443\u0447\u0430\u0435\u0432, \u043a\u043e\u0433\u0434\u0430 \u043f\u0430\u043c\u044f\u0442\u044c \u0431\u044b\u043b\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0430 \u0432 .NET, \u0431\u0443\u0444\u0435\u0440 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d (pinned) \u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u0449\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u0438 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u0438 GC, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b <code>MemoryHandle<\/code>, \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u0432 \u0441\u0435\u0431\u0435 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u043e\u0442\u0440\u0435\u0437\u043a\u0430 \u0436\u0438\u0437\u043d\u0438 <code>GCHandle<\/code>, \u0437\u0430\u043a\u0440\u0435\u043f\u0438\u0432\u0448\u0435\u0433\u043e \u0431\u0443\u0444\u0435\u0440 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438:<\/li>\n<\/ul>\n<p>  <\/p>\n<pre><code>public unsafe struct MemoryHandle : IDisposable {     private void* _pointer;     private GCHandle _handle;     private IPinnable _pinnable;      \/\/\/ &lt;summary&gt;     \/\/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u0442 MemoryHandle \u0434\u043b\u044f \u0443\u0447\u0430\u0441\u0442\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438     \/\/\/ &lt;\/summary&gt;     public MemoryHandle(void* pointer, GCHandle handle = default, IPinnable pinnable = default)     {         _pointer = pointer;         _handle = handle;         _pinnable = pinnable;     }      \/\/\/ &lt;summary&gt;     \/\/\/ \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043a\u0430\u043a \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d \u0438 \u0434\u0430\u043d\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u043d\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f     \/\/\/ &lt;\/summary&gt;     [CLSCompliant(false)]     public void* Pointer =&gt; _pointer;      \/\/\/ &lt;summary&gt;     \/\/\/ \u041e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442 _handle \u0438 _pinnable, \u0442\u0430\u043a\u0436\u0435 \u0441\u0431\u0440\u0430\u0441\u044b\u0432\u0430\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043f\u0430\u043c\u044f\u0442\u044c     \/\/\/ &lt;\/summary&gt;     public void Dispose()     {         if (_handle.IsAllocated)         {             _handle.Free();         }          if (_pinnable != null)         {             _pinnable.Unpin();             _pinnable = null;         }          _pointer = null;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441\u043e \u0432\u0441\u0435\u043c \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u0418 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445, \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0441\u0430\u043c\u0443 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <code>Memory&lt;T&gt;<\/code> (\u043f\u043e\u043a\u0430\u0437\u0430\u043d\u044b \u043d\u0435 \u0432\u0441\u0435 \u0447\u043b\u0435\u043d\u044b \u0442\u0438\u043f\u0430, \u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u0432\u0448\u0438\u0435\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u0430\u0436\u043d\u044b\u043c\u0438):<\/p>\n<p>  <\/p>\n<pre><code>    public readonly struct Memory&lt;T&gt;     {         private readonly object _object;         private readonly int _index, _length;          public Memory(T[] array) { ... }         public Memory(T[] array, int start, int length) { ... }         internal Memory(MemoryManager&lt;T&gt; manager, int length) { ... }         internal Memory(MemoryManager&lt;T&gt; manager, int start, int length) { ... }          public int Length =&gt; _length &amp; RemoveFlagsBitMask;         public bool IsEmpty =&gt; (_length &amp; RemoveFlagsBitMask) == 0;          public Memory&lt;T&gt; Slice(int start, int length);         public void CopyTo(Memory&lt;T&gt; destination) =&gt; Span.CopyTo(destination.Span);         public bool TryCopyTo(Memory&lt;T&gt; destination) =&gt; Span.TryCopyTo(destination.Span);     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u044f \u0440\u0435\u0448\u0438\u043b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0435\u0449\u0435 \u0434\u0432\u0430 <code>internal<\/code> \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0442\u0438\u043f\u0430, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0435\u0449\u0435 \u043e\u0434\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u2014 <code>MemoryManager<\/code>, \u0440\u0435\u0447\u044c \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u0439\u0434\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u0447\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0435\u043c-\u0442\u043e, \u043e \u0447\u0435\u043c \u0432\u044b, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u043b\u0438: \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u043e\u043c \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e, \u043a\u0430\u043a \u0438 <code>Span<\/code>, <code>Memory<\/code> \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0438 \u0440\u0430\u0437\u043c\u0435\u0440 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0431\u0443\u0444\u0435\u0440\u0430. \u0422\u0430\u043a\u0436\u0435, \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0447\u0442\u043e <code>Memory<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c <code>new<\/code> \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043f\u043b\u044e\u0441 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u2014 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0438, \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438 <code>ArraySegment<\/code>. \u0422.\u0435. \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 unmanaged \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043d\u0435 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f. \u041e\u0434\u043d\u0430\u043a\u043e, \u043a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u043a\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 <code>MemoryManager<\/code>:<\/p>\n<p>  <\/p>\n<p><strong>\u0424\u0430\u0439\u043b <a href=\"https:\/\/github.com\/dotnet\/corefx\/blob\/master\/src\/Common\/src\/CoreLib\/System\/Buffers\/MemoryManager.cs\">MemoryManager.cs<\/a><\/strong><\/p>\n<p>  <\/p>\n<pre><code>public abstract class MemoryManager&lt;T&gt; : IMemoryOwner&lt;T&gt;, IPinnable {     public abstract MemoryHandle Pin(int elementIndex = 0);     public abstract void Unpin();      public virtual Memory&lt;T&gt; Memory =&gt; new Memory&lt;T&gt;(this, GetSpan().Length);     public abstract Span&lt;T&gt; GetSpan();     protected Memory&lt;T&gt; CreateMemory(int length) =&gt; new Memory&lt;T&gt;(this, length);     protected Memory&lt;T&gt; CreateMemory(int start, int length) =&gt; new Memory&lt;T&gt;(this, start, length);      void IDisposable.Dispose()     protected abstract void Dispose(bool disposing); }<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u042f \u043f\u043e\u0437\u0432\u043e\u043b\u044e \u0441\u0435\u0431\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043f\u043e\u0440\u0438\u0442\u044c \u0441 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u0432\u0435\u043b\u0438 \u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 CLR, \u043d\u0430\u0437\u0432\u0430\u0432 \u0442\u0438\u043f \u0438\u043c\u0435\u043d\u0435\u043c MemoryManager. \u041a\u043e\u0433\u0434\u0430 \u044f \u0435\u0433\u043e \u0443\u0432\u0438\u0434\u0435\u043b, \u0442\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0435\u0448\u0438\u043b \u0447\u0442\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0447\u0442\u043e-\u0442\u043e \u0442\u0438\u043f\u0430 \u043c\u0435\u043d\u0435\u0434\u0436\u043c\u0435\u043d\u0442\u0430 \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u043e \u0440\u0443\u0447\u043d\u043e\u0433\u043e, \u043e\u0442\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043e\u0442 LOH\/SOH. \u041d\u043e \u0431\u044b\u043b \u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u043e\u0447\u0430\u0440\u043e\u0432\u0430\u043d, \u0443\u0432\u0438\u0434\u0435\u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0441\u0442\u043e\u0438\u043b\u043e \u043d\u0430\u0437\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e \u0430\u043d\u0430\u043e\u043b\u0433\u0438\u0438 \u0441 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c: MemoryOwner.  <\/p><\/blockquote>\n<p>\u041a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u0432 \u0441\u0435\u0431\u0435 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 \u0443\u0447\u0430\u0441\u0442\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u0435\u0441\u043b\u0438 <code>Span<\/code> \u2014 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e, <code>Memory<\/code> \u2014 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u0443\u0447\u0430\u0441\u0442\u043a\u0435, \u0442\u043e <code>MemoryManager<\/code> \u2014 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0435\u0433\u043e \u0436\u0438\u0437\u043d\u0438, \u0435\u0433\u043e \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0442\u0438\u043f <code>NativeMemoryManager&lt;T&gt;<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u043e\u0442\u044c \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0435 \u043f\u043b\u043e\u0445\u043e \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u0441\u0443\u0442\u044c \u043f\u043e\u043d\u044f\u0442\u0438\u044f &#171;\u0432\u043b\u0430\u0434\u0435\u043d\u0438\u0435&#187;:<\/p>\n<p>  <\/p>\n<p><strong>\u0424\u0430\u0439\u043b <a href=\"https:\/\/github.com\/dotnet\/corefx\/blob\/888088448ac5dd1053d88434dfd819dcbc0fd9a1\/src\/Common\/tests\/System\/Buffers\/NativeMemoryManager.cs\">NativeMemoryManager.cs<\/a><\/strong><\/p>\n<p>  <\/p>\n<pre><code>internal sealed class NativeMemoryManager : MemoryManager&lt;byte&gt; {     private readonly int _length;     private IntPtr _ptr;     private int _retainedCount;     private bool _disposed;      public NativeMemoryManager(int length)     {         _length = length;         _ptr = Marshal.AllocHGlobal(length);     }      public override void Pin() { ... }      public override void Unpin()     {         lock (this)         {             if (_retainedCount &gt; 0)             {                 _retainedCount--;                 if (_retainedCount == 0)                 {                     if (_disposed)                     {                         Marshal.FreeHGlobal(_ptr);                         _ptr = IntPtr.Zero;                     }                 }             }         }     }      \/\/ \u0414\u0440\u0443\u0433\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422.\u0435., \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043a\u043b\u0430\u0441\u0441 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 <code>Pin()<\/code> \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0449\u0438\u0435\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u0438\u0437 <code>unsafe<\/code> \u043c\u0438\u0440\u0430.<\/p>\n<p>  <\/p>\n<p>\u0415\u0449\u0435 \u043e\u0434\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e, \u0442\u0435\u0441\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u0441 <code>Memory<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>MemoryPool<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043f\u0443\u043b\u0438\u043d\u0433 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 <code>MemoryManager<\/code> (\u0430 \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u2014 <code>IMemoryOwner<\/code>):<\/p>\n<p>  <\/p>\n<p><strong>\u0424\u0430\u0439\u043b <a href=\"https:\/\/github.com\/dotnet\/corefx\/blob\/f592e887e2349ed52af6a83070c42adb9d26408c\/src\/System.Memory\/src\/System\/Buffers\/MemoryPool.cs\">MemoryPool.cs<\/a><\/strong><\/p>\n<p>  <\/p>\n<pre><code>public abstract class MemoryPool&lt;T&gt; : IDisposable {     public static MemoryPool&lt;T&gt; Shared =&gt; s_shared;      public abstract IMemoryOwner&lt;T&gt; Rent(int minBufferSize = -1);      public void Dispose() { ... } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0432\u044b\u0434\u0430\u0447\u0438 \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435. \u0410\u0440\u0435\u043d\u0434\u0443\u0435\u043c\u044b\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>IMemoryOwner&lt;T&gt;<\/code> \u0438\u043c\u0435\u044e\u0442 \u043c\u0435\u0442\u043e\u0434 <code>Dispose()<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0430\u0440\u0435\u043d\u0434\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u043f\u0443\u043b \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432. \u041f\u0440\u0438\u0447\u0435\u043c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0431\u0449\u0438\u043c \u043f\u0443\u043b\u043e\u043c \u0431\u0443\u0444\u0435\u0440\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 <code>ArrayMemoryPool<\/code>:<\/p>\n<p>  <\/p>\n<p><strong>\u0424\u0430\u0439\u043b <a href=\"https:\/\/github.com\/dotnet\/corefx\/blob\/56dfb8834fa50f3bc61ea9b4bfdc9dcc759b6ec9\/src\/System.Memory\/src\/System\/Buffers\/ArrayMemoryPool.cs\">ArrayMemoryPool.cs<\/a><\/strong><\/p>\n<p>  <\/p>\n<pre><code>internal sealed partial class ArrayMemoryPool&lt;T&gt; : MemoryPool&lt;T&gt; {     private const int MaximumBufferSize = int.MaxValue;     public sealed override int MaxBufferSize =&gt; MaximumBufferSize;     public sealed override IMemoryOwner&lt;T&gt; Rent(int minimumBufferSize = -1)     {         if (minimumBufferSize == -1)             minimumBufferSize = 1 + (4095 \/ Unsafe.SizeOf&lt;T&gt;());         else if (((uint)minimumBufferSize) &gt; MaximumBufferSize)             ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.minimumBufferSize);          return new ArrayMemoryPoolBuffer(minimumBufferSize);     }     protected sealed override void Dispose(bool disposing) { } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0438\u0438 \u0443\u0432\u0438\u0434\u0435\u043d\u043d\u043e\u0433\u043e, \u0432\u044b\u0440\u0438\u0441\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u0430 \u043c\u0438\u0440\u0430:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0422\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 <code>Span<\/code> \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0435 \u043b\u0438\u0431\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 (<code>ReadOnlySpan<\/code>), \u043b\u0438\u0431\u043e \u0437\u0430\u043f\u0438\u0441\u044c (<code>Span<\/code>). \u041d\u043e \u043d\u0435 \u0437\u0430\u0434\u0430\u0447\u0443 \u0435\u0433\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432 \u043f\u043e\u043b\u0435 \u043a\u043b\u0430\u0441\u0441\u0430 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c<\/li>\n<li>\u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0431\u0443\u0444\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043f\u043e\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0430, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Memory&lt;T&gt;<\/code> \u0438\u043b\u0438 <code>ReadOnlyMemory&lt;T&gt;<\/code> \u2014 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0446\u0435\u043b\u0435\u0439<\/li>\n<li><code>MemoryManager&lt;T&gt;<\/code> \u2014 \u044d\u0442\u043e \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446 \u0431\u0443\u0444\u0435\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c: \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438). \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c, \u043a\u043e\u0433\u0434\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0441\u0442\u0430\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u044b <code>Pin()<\/code>. \u0418\u043b\u0438 \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u043b\u0430\u0434\u0430\u0442\u044c \u0437\u043d\u0430\u043d\u0438\u044f\u043c\u0438 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c<\/li>\n<li>\u0415\u0441\u043b\u0438 <code>Memory<\/code> \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d \u0432\u043e\u043a\u0440\u0443\u0433 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u0443\u0447\u0430\u0441\u0442\u043a\u0430 \u043f\u0430\u043c\u044f\u0442\u0438, <code>Pin()<\/code> \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u0442. \u041e\u0434\u043d\u0430\u043a\u043e, \u044d\u0442\u043e \u0443\u043d\u0438\u0444\u0438\u0446\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0431\u0443\u0444\u0435\u0440\u043e\u0432: \u043a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u0442\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c <\/li>\n<li>\u041a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0442\u0438\u043f\u043e\u0432 \u0438\u043c\u0435\u0435\u0442 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b. \u0410 \u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a <code>Span<\/code> \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u0442\u0430\u043a \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0435\u0433\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0438\u0437 <code>Memory<\/code>. \u0421\u0430\u043c <code>Memory<\/code> \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u0442\u0430\u043a \u0438 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0435\u0433\u043e <code>IMemoryOwner<\/code> \u0442\u0438\u043f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u043b\u0430\u0434\u0435\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u043a\u043e\u043c \u043f\u0430\u043c\u044f\u0442\u0438, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f <code>Memory<\/code>. \u0427\u0430\u0441\u0442\u043d\u044b\u043c \u0441\u043b\u0443\u0447\u0430\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u043b\u044e\u0431\u043e\u0439 \u0442\u0438\u043f, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 <code>MemoryManager<\/code>: \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u043b\u0430\u0434\u0435\u043d\u0438\u0435 \u0443\u0447\u0430\u0441\u0442\u043a\u043e\u043c \u043f\u0430\u043c\u044f\u0442\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u043f\u043e\u0434\u0441\u0447\u0435\u0442\u043e\u043c \u0441\u0441\u044b\u043b\u043e\u043a \u0438\u0437 <code>unsafe<\/code> \u043c\u0438\u0440\u0430). \u0415\u0441\u043b\u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c \u043f\u0443\u043b\u043b\u0438\u043d\u0433 \u0442\u0430\u043a\u0438\u0445 \u0431\u0443\u0444\u0435\u0440\u043e\u0432 (\u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044b\u0439 \u0442\u0440\u0430\u0444\u0444\u0438\u043a \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0440\u0430\u0432\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430), \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0437\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0438\u043f\u043e\u043c <code>MemoryPool<\/code>.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442\u0441\u044f \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 <code>unsafe<\/code> \u043a\u043e\u0434\u043e\u043c, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0442\u0443\u0434\u0430 \u043d\u0435\u043a\u0438\u0439 \u0431\u0443\u0444\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f <code>Memory<\/code>: \u043e\u043d \u0438\u043c\u0435\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 <code>Pin<\/code>, \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0444\u0438\u043a\u0441\u0430\u0446\u0438\u044e \u0431\u0443\u0444\u0435\u0440\u0430 \u0432 \u043a\u0443\u0447\u0435 .NET, \u0435\u0441\u043b\u0438 \u0442\u043e\u0442 \u0431\u044b\u043b \u0442\u0430\u043c \u0441\u043e\u0437\u0434\u0430\u043d.<\/li>\n<li>\u0415\u0441\u043b\u0438 \u0436\u0435 \u0432\u044b \u0438\u043c\u0435\u0435\u0442\u0435 \u043d\u0435\u043a\u0438\u0439 \u0442\u0440\u0430\u0444\u0438\u043a \u0431\u0443\u0444\u0435\u0440\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u0440\u0435\u0448\u0430\u0435\u0442\u0435 \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0442\u0435\u043a\u0441\u0442\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u043b\u0438 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e DSL), \u0441\u0442\u043e\u0438\u0442 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u0438\u043f\u043e\u043c <code>MemoryPool<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u044b\u0434\u0430\u0432\u0430\u044f \u0438\u0437 \u043f\u0443\u043b\u0430 \u0431\u0443\u0444\u0435\u0440\u044b \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u0435\u0441\u043b\u0438 \u043d\u0435 \u043d\u0430\u0448\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e, \u043d\u043e \u0441 \u043e\u0431\u0440\u0435\u0437\u043a\u043e\u0439 <code>originalMemory.Slice(requiredSize)<\/code> \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0443\u043b)<\/li>\n<\/ul>\n<p>  <\/p>\n<blockquote>\n<h3>\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0432\u0441\u044e \u043a\u043d\u0438\u0433\u0443<\/h3>\n<p>  <\/p>\n<ul>\n<li><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/3q\/6g\/qa\/3q6gqaz40qx-jzscjf3jbxatxhg.png\"> CLR Book: <a href=\"https:\/\/github.com\/sidristij\/dotnetbook\/\">GitHub<\/a><\/li>\n<li><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/eo\/6g\/eo\/eo6geog0tg5ernqmv2lcmufefta.png\"> \u0420\u0435\u043b\u0438\u0437 0.5.0 \u043a\u043d\u0438\u0433\u0438, PDF: <a href=\"https:\/\/github.com\/sidristij\/dotnetbook\/releases\/tag\/0.5.0\">GitHub Release<\/a><\/li>\n<\/ul>\n<p>  <\/p><\/blockquote>\n<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <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\/post\/420051\/\"> https:\/\/habr.com\/post\/420051\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/420051\/\" class=\"post__text post__text-html js-mediator-article\">\n<p><img decoding=\"async\" width=\"350\" src=\"https:\/\/habrastorage.org\/webt\/34\/ua\/e6\/34uae6usmglyw10vxga3sgfgh8c.jpeg\" align=\"left\"> \u042d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u0446\u0435\u043b\u0443\u044e \u0441\u0435\u0440\u0438\u044e \u0441\u0442\u0430\u0442\u0435\u0439, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u043a\u043d\u0438\u0433\u0430 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 .NET CLR, \u0438 .NET \u0432 \u0446\u0435\u043b\u043e\u043c. \u0417\u0430 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u2014 \u0434\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u043f\u043e \u043a\u0430\u0442.<\/p>\n<p>  <\/p>\n<h2 id=\"memorylttgt-i-readonlymemorylttgt\">Memory&lt;T&gt; \u0438 ReadOnlyMemory&lt;T&gt;<\/h2>\n<p>  <\/p>\n<p>\u0412\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0442\u043b\u0438\u0447\u0438\u0439 <code>Memory&lt;T&gt;<\/code> \u043e\u0442 <code>Span&lt;T&gt;<\/code> \u0434\u0432\u0430. \u041f\u0435\u0440\u0432\u043e\u0435 \u2014 \u0442\u0438\u043f <code>Memory&lt;T&gt;<\/code> \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f <code>ref<\/code> \u0432 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0442\u0438\u043f\u0430. \u0422.\u0435., \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0442\u0438\u043f <code>Memory&lt;T&gt;<\/code> \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u0430\u0432\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0441\u0442\u0435\u043a\u0435, \u044f\u0432\u043b\u044f\u044f\u0441\u044c \u043b\u0438\u0431\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043b\u0438\u0431\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0430 \u043b\u0438\u0431\u043e \u0435\u0433\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c, \u043d\u043e \u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043a\u0443\u0447\u0435, \u0441\u0441\u044b\u043b\u0430\u044f\u0441\u044c \u043e\u0442\u0442\u0443\u0434\u0430 \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u044d\u0442\u0430 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0430\u044f \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0433\u0440\u043e\u043c\u043d\u0443\u044e \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u0432 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u0445 <code>Memory&lt;T&gt;<\/code> \u0432 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0441 <code>Span&lt;T&gt;<\/code>. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 <code>Span&lt;T&gt;<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 <em>\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f<\/em> \u043d\u0435\u043a\u0438\u043c \u0431\u0443\u0444\u0435\u0440\u043e\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0442\u0438\u043f <code>Memory&lt;T&gt;<\/code> \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f <em>\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f<\/em> \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0431\u0443\u0444\u0435\u0440\u0435, \u0430 \u043d\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c.<\/p>\n<p>  <\/p>\n<blockquote><p>\u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u2014 \u0432\u0442\u043e\u0440\u0430\u044f \u0438\u0437 \u0446\u0438\u043a\u043b\u0430 \u043f\u0440\u043e Span&lt;T&gt; \u0438 Memory&lt;T&gt;. \u041e\u043d\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u0432\u043e\u0434\u043d\u043e\u0439 \u0434\u043b\u044f Memory&lt;T&gt; \u0432 \u0442\u043e\u043c \u043f\u043b\u0430\u043d\u0435 \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u044f \u0440\u0435\u0448\u0438\u043b \u0440\u0430\u0441\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0449\u0443\u044e \u0442\u0435\u0440\u043c\u0438\u043d\u0438\u043b\u043e\u0433\u0438\u044e, \u0430 \u0432\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u2014 \u0440\u0435\u0448\u0438\u043b \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e  <\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/post\/418911\/\">Span&lt;T&gt;: \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 .NET<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/post\/420051\/\">Span&lt;T&gt; Memory&lt;T&gt; \u0438 ReadOnlyMemory&lt;T&gt;<\/a> (\u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f)<\/li>\n<li>\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Span&lt;T&gt; \u0438 Memory&lt;T&gt;<\/li>\n<\/ul>\n<p>  <\/p><\/blockquote>\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-287359","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287359","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=287359"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/287359\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=287359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=287359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=287359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}