{"id":345030,"date":"2023-02-06T09:03:15","date_gmt":"2023-02-06T09:03:15","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=345030"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=345030","title":{"rendered":"<span>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0432\u043e\u0438\u043c\u0438 \u0440\u0443\u043a\u0430\u043c\u0438 \u0432 c#<\/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>\u0421\u0435\u0439\u0447\u0430\u0441 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043c\u0435\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440, \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u044f\u0437\u044b\u043a\u0430. \u0422.\u0435. \u0432\u043c\u0435\u0441\u0442\u043e <strong>Array.Resize<\/strong> \u0438 <strong>var array = new int[100]<\/strong> \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u044f\u043c\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 unsafe \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u042d\u0442\u0430 \u0437\u0430\u043c\u0435\u0442\u043a\u0430 \u043d\u043e\u0441\u0438\u0442 \u0430\u043a\u0430\u0434\u0435\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440. \u0412\u0440\u044f\u0434 \u043b\u0438 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0447\u043d\u0443 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432. \u0427\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0440\u0430\u0434\u0438 \u0447\u0435\u0433\u043e \u0432\u0441\u0451 \u044d\u0442\u043e.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/56c\/92a\/86e\/56c92a86ee03844a29f1cacc209650bc.png\" width=\"445\" height=\"426\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/56c\/92a\/86e\/56c92a86ee03844a29f1cacc209650bc.png\"\/><figcaption><\/figcaption><\/figure>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/435\/3ae\/8a6\/4353ae8a6917cc0787c4cfab9c63cd4f.png\" alt=\"\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0441 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u043c\u0438.\" title=\"\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0441 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u043c\u0438.\" width=\"504\" height=\"688\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/435\/3ae\/8a6\/4353ae8a6917cc0787c4cfab9c63cd4f.png\"\/><figcaption>\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0441 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/figcaption><\/figure>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c3a\/509\/2db\/c3a5092dbb8c3e49adcc391d33647359.png\" alt=\"\u0418 \u0432\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430.\" title=\"\u0418 \u0432\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430.\" width=\"504\" height=\"688\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c3a\/509\/2db\/c3a5092dbb8c3e49adcc391d33647359.png\"\/><figcaption>\u0418 \u0432\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430.<\/figcaption><\/figure>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 ArrayNoGarbage. \u041d\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430. \u041d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c unsafe \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u0418 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 NuGet \u043f\u0430\u043a\u0435\u0442 System.Runtime.CompilerServices.Unsafe \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0435\u0449\u0451 \u043d\u0435\u0442 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u041a\u043b\u0430\u0441\u0441 Unsafe \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0435 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c\u0438 \u0438 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<p>\u041f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439. \u0412\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438 (\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435), \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043c\u0430\u0441\u0441\u0438\u0432 \u0438 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u041f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0434\u043b\u0438\u043d\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0431\u0443\u0434\u0435\u043c \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u0438\u043d\u0443. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 null \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0438 \u043f\u043e\u0434\u0441\u0443\u043d\u0435\u043c \u0435\u043c\u0443 \u043d\u0430\u0448 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \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\/8af\/b83\/792\/8afb83792a007286ca0f42d29920013a.png\" alt=\"\u0423\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441 \u0441\u0430\u0439\u0442\u0430 microsoft.\" title=\"\u0423\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441 \u0441\u0430\u0439\u0442\u0430 microsoft.\" width=\"565\" height=\"601\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8af\/b83\/792\/8afb83792a007286ca0f42d29920013a.png\"\/><figcaption>\u0423\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441 \u0441\u0430\u0439\u0442\u0430 microsoft.<\/figcaption><\/figure>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c generic \u043a\u043b\u0430\u0441\u0441 ArrayNoGarbage, \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0435 \u0451\u043c\u043a\u043e\u0441\u0442\u044c. \u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u044d\u0442\u0443 \u0451\u043c\u043a\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0434\u043b\u0438\u043d\u044b.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 generic \u0442\u0438\u043f\u043e\u0432 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e unmanaged \u0442\u0438\u043f\u044b.<\/p>\n<p>\u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c \u0431\u0443\u0434\u0435\u0442 generic \u043c\u0430\u0441\u0441\u0438\u0432. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434 \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0435\u0431\u044f \u043e\u0442 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u0435\u0434\u0436\u043c\u0435\u043d\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 \u043a\u043b\u0430\u0441\u0441 Marshal. \u0410 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a Object Header \u0438 Method Table Ptr. \u0427\u0430\u0441\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043f\u043e\u0434 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u041f\u043e\u0434 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u041b\u0438\u0431\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0451\u043c\u043a\u043e\u0441\u0442\u044c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430. \u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u043e\u0433\u043e, \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 ArrayNoGarbage \u0441 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438.<\/p>\n<pre><code class=\"cs\">using System; using System.Runtime.CompilerServices;  \/\/\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0440\u0443\u0433\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f null \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u0438 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f. #pragma warning disable CS8618 #pragma warning disable CS8601 public sealed unsafe class ArrayNoGarbage&lt;T> where T : unmanaged {     \/\/\u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u043b\u044f \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0445 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.     private T[] storage;          \/\/\u042d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.     \/\/\u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043d \u043d\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0435\u0441\u0442\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438.     private T[] array;          \/\/\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u0434 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.     private readonly int elementOffset;          \/\/\u0420\u0430\u0437\u043c\u0435\u0440 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a Object Header, Method Table Ptr \u0438 \u0434\u043b\u0438\u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.     private readonly int ptrOffset;          \/\/\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430.     private const int MIN_CAPACITY = 64;      public ArrayNoGarbage(int capacity = MIN_CAPACITY)     {         \/\/\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0451\u043c\u043a\u043e\u0441\u0442\u044c\u044e. \u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u2013 \u043d\u0435 \u043c\u0430\u0441\u0441\u0438\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e.          storage = new T[capacity &lt; MIN_CAPACITY ? MIN_CAPACITY : capacity];                  \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435.         var storageObjPtr = (IntPtr*) Unsafe.AsPointer(ref storage);         \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430.         var storageHeaderPtr = (*storageObjPtr).ToPointer();         \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430.         var storageElement0Ptr = Unsafe.AsPointer(ref storage[0]);          \/\/\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.         ptrOffset = (int) ((((IntPtr) storageElement0Ptr).ToInt64() -                             ((IntPtr) storageHeaderPtr).ToInt64()) \/ sizeof(nint));         \/\/\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0432 \u043a\u0430\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043f\u043e\u043c\u0435\u0441\u0442\u044f\u0442\u0441\u044f \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.         elementOffset = sizeof(nint) * ptrOffset &lt;= sizeof(T)             ? 1             : sizeof(nint) * ptrOffset \/ sizeof(T);                  \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430.         \/\/Unsafe.Add \u0438 Unsafe.Subtract \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e.         var arrayElement0Ptr = Unsafe.Add&lt;T>(storageElement0Ptr, elementOffset);         \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0430.         var arrayHeaderPtr = (nint*) Unsafe.Subtract&lt;nint>(arrayElement0Ptr, ptrOffset);          \/\/\u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430,         \/\/\u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043e\u043d\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430,         \/\/\u0430 \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0436\u0438\u0442\u044c \u0441\u0432\u043e\u0435\u0439 \u0436\u0438\u0437\u043d\u044c\u044e.         for (var i = 0; i &lt; ptrOffset; i++)         {             arrayHeaderPtr[i] = ((nint*) storageHeaderPtr)[i];         }          \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0434\u043b\u0438\u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.         var lengthPtr = (int*) Unsafe.Subtract&lt;nint>(arrayElement0Ptr, 1);         \/\/\u0423\u0441\u0442\u0430\u043d\u0430\u043b\u0438\u0432\u0430\u0435\u043c \u0434\u043b\u0438\u043d\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0437\u0430 \u0432\u044b\u0447\u0435\u0442\u043e\u043c \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.         lengthPtr[0] = storage.Length - elementOffset;                  \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432. \u0421\u0435\u0439\u0447\u0430\u0441 \u043e\u043d \u0440\u0430\u0432\u0435\u043d null. \u0418 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 IntPtr.Zero.         var arrayObjPtr = (nint*) Unsafe.AsPointer(ref array);         \/\/\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 null.         arrayObjPtr[0] = (nint) arrayHeaderPtr;     }      public T[] GetArray(int length)     {         \/\/\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0434\u043b\u0438\u043d\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u043c.         if (length == array.Length) return array;                  \/\/\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0435\u043c\u043a\u043e\u0441\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0434 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435,         \/\/\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430.         if (length > storage.Length - elementOffset)         {             \/\/Array.Resize \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u0451\u043c\u043a\u043e\u0441\u0442\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0443\u044e \u0451\u043c\u043a\u043e\u0441\u0442\u044c.             \/\/\u042d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043a \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u044f\u043c \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435.             Array.Resize(ref storage, length + elementOffset);                          \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430.             var storageElement0Ptr = Unsafe.AsPointer(ref storage[0]);             \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.             var arrayElement0Ptr = Unsafe.Add&lt;T>(storageElement0Ptr, elementOffset);             \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0430.             var arrayHeaderPtr = Unsafe.Subtract&lt;nint>(arrayElement0Ptr, ptrOffset);             \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432.             var arrayObjPtr = (nint*) Unsafe.AsPointer(ref array);              \/\/\u0420\u0430\u0437\u043c\u0435\u0440 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0431\u044b\u043b \u0438\u0437\u043c\u0435\u043d\u0451\u043d,             \/\/\u043d\u0430\u0448 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0435\u0439\u0447\u0430\u0441 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0440\u044b\u0439 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438.             \/\/\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0430.             \/\/\u0421\u0442\u0430\u0440\u044b\u0439 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0438\u0449\u0435\u043d \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u043e\u043c \u043c\u0443\u0441\u043e\u0440\u0430             \/\/\u043d\u0430 \u043d\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043d\u0438 \u043d\u0430\u0448 \u043c\u0430\u0441\u0441\u0438\u0432.             arrayObjPtr[0] = (nint) arrayHeaderPtr;         }                  {             \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.             var arrayElement0Ptr = Unsafe.AsPointer(ref array[0]);             \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0434\u043b\u0438\u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.             var lengthPtr = (int*) Unsafe.Subtract&lt;IntPtr>(arrayElement0Ptr, 1);             \/\/\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0434\u043b\u0438\u043d\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.             lengthPtr[0] = length;         }                  return array;     } } #pragma warning restore CS8618 #pragma warning restore CS8601<\/code><\/pre>\n<p>\u042f \u043d\u0435 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 32 \u0431\u0438\u0442\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0445\u0438\u0442\u0440\u044b\u0445 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0432\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0431\u0435\u0437 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0443\u0441\u043e\u0440\u0430.<\/p>\n<\/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\/post\/715020\/\"> https:\/\/habr.com\/ru\/post\/715020\/<\/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>\u0421\u0435\u0439\u0447\u0430\u0441 \u044f \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043c\u0435\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440, \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u044f\u0437\u044b\u043a\u0430. \u0422.\u0435. \u0432\u043c\u0435\u0441\u0442\u043e <strong>Array.Resize<\/strong> \u0438 <strong>var array = new int[100]<\/strong> \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u044f\u043c\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 unsafe \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u042d\u0442\u0430 \u0437\u0430\u043c\u0435\u0442\u043a\u0430 \u043d\u043e\u0441\u0438\u0442 \u0430\u043a\u0430\u0434\u0435\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440. \u0412\u0440\u044f\u0434 \u043b\u0438 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u044d\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0447\u043d\u0443 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432. \u0427\u0442\u043e\u0431\u044b \u043b\u0443\u0447\u0448\u0435 \u0431\u044b\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0440\u0430\u0434\u0438 \u0447\u0435\u0433\u043e \u0432\u0441\u0451 \u044d\u0442\u043e.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<figure class=\"\"><figcaption>\u0412\u043e\u0442 \u0442\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u0441 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u043c\u0438.<\/figcaption><\/figure>\n<figure class=\"\"><figcaption>\u0418 \u0432\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0441\u043b\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430.<\/figcaption><\/figure>\n<p>\u042d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0447\u0442\u043e \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 ArrayNoGarbage. \u041d\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c.<\/p>\n<h3>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h3>\n<p>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430. \u041d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c unsafe \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442. \u0418 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 NuGet \u043f\u0430\u043a\u0435\u0442 System.Runtime.CompilerServices.Unsafe \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0435\u0449\u0451 \u043d\u0435\u0442 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u041a\u043b\u0430\u0441\u0441 Unsafe \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0435 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c\u0438 \u0438 \u043d\u0435\u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u043c\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<p>\u041f\u043b\u0430\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439. \u0412\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438 (\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435), \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d \u043c\u0430\u0441\u0441\u0438\u0432 \u0438 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435. \u041f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0434\u043b\u0438\u043d\u044b \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0431\u0443\u0434\u0435\u043c \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u0438\u043d\u0443. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 null \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0438 \u043f\u043e\u0434\u0441\u0443\u043d\u0435\u043c \u0435\u043c\u0443 \u043d\u0430\u0448 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<figure class=\"full-width\"><figcaption>\u0423\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u0418\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441 \u0441\u0430\u0439\u0442\u0430 microsoft.<\/figcaption><\/figure>\n<p>\u0421\u043e\u0437\u0434\u0430\u0451\u043c generic \u043a\u043b\u0430\u0441\u0441 ArrayNoGarbage, \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0435\u0435 \u0451\u043c\u043a\u043e\u0441\u0442\u044c. \u0412 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u044d\u0442\u0443 \u0451\u043c\u043a\u043e\u0441\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u043c\u0435\u043d\u044c\u0448\u0435 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0434\u043b\u0438\u043d\u044b.<\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 generic \u0442\u0438\u043f\u043e\u0432 \u0431\u0443\u0434\u0435\u043c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e unmanaged \u0442\u0438\u043f\u044b.<\/p>\n<p>\u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c \u0431\u0443\u0434\u0435\u0442 generic \u043c\u0430\u0441\u0441\u0438\u0432. \u042d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434 \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0435\u0431\u044f \u043e\u0442 \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u0435\u0434\u0436\u043c\u0435\u043d\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 \u043a\u043b\u0430\u0441\u0441 Marshal. \u0410 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0440\u0443\u0447\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a Object Header \u0438 Method Table Ptr. \u0427\u0430\u0441\u0442\u044c \u044d\u0442\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043f\u043e\u0434 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u041f\u043e\u0434 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c\u0441\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u041b\u0438\u0431\u043e \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0451\u043c\u043a\u043e\u0441\u0442\u044c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430. \u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u043e\u0433\u043e, \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442.<\/p>\n<p>\u041d\u0438\u0436\u0435 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 ArrayNoGarbage \u0441 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438.<\/p>\n<pre><code class=\"cs\">using System; using System.Runtime.CompilerServices;  \/\/\u041a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0440\u0443\u0433\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f null \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u0430\u0432\u043b\u044f\u0435\u043c \u044d\u0442\u0438 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u044f. #pragma warning disable CS8618 #pragma warning disable CS8601 public sealed unsafe class ArrayNoGarbage&lt;T> where T : unmanaged {     \/\/\u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u043b\u044f \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0445 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.     private T[] storage;          \/\/\u042d\u0442\u043e\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438 \u044f\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0434\u0430\u043d\u043d\u044b\u0445.     \/\/\u0424\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043e\u043d \u043d\u0435 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0435\u0441\u0442\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438.     private T[] array;          \/\/\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u0434 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.     private readonly int elementOffset;          \/\/\u0420\u0430\u0437\u043c\u0435\u0440 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a Object Header, Method Table Ptr \u0438 \u0434\u043b\u0438\u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.     private readonly int ptrOffset;          \/\/\u041c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430.     private const int MIN_CAPACITY = 64;      public ArrayNoGarbage(int capacity = MIN_CAPACITY)     {         \/\/\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0441 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0439 \u0451\u043c\u043a\u043e\u0441\u0442\u044c\u044e. \u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u2013 \u043d\u0435 \u043c\u0430\u0441\u0441\u0438\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e.          storage = new T[capacity &lt; MIN_CAPACITY ? MIN_CAPACITY : capacity];                  \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435.         var storageObjPtr = (IntPtr*) Unsafe.AsPointer(ref storage);         \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430.         var storageHeaderPtr = (*storageObjPtr).ToPointer();         \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430.         var storageElement0Ptr = Unsafe.AsPointer(ref storage[0]);          \/\/\u041d\u0430\u0445\u043e\u0434\u0438\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.         ptrOffset = (int) ((((IntPtr) storageElement0Ptr).ToInt64() -                             ((IntPtr) storageHeaderPtr).ToInt64()) \/ sizeof(nint));         \/\/\u0412\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u043c \u0432 \u043a\u0430\u043a\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043f\u043e\u043c\u0435\u0441\u0442\u044f\u0442\u0441\u044f \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435.         elementOffset = sizeof(nint) * ptrOffset &lt;= sizeof(T)             ? 1             : sizeof(nint) * ptrOffset \/ sizeof(T);                  \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430.         \/\/Unsafe.Add \u0438 Unsafe.Subtract \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u044e\u0442 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e.         var arrayElement0Ptr = Unsafe.Add&lt;T>(storageElement0Ptr, elementOffset);         \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0430.         var arrayHeaderPtr = (nint*) Unsafe.Subtract&lt;nint>(arrayElement0Ptr, ptrOffset);          \/\/\u041a\u043e\u043f\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430,         \/\/\u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043e\u043d\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430,         \/\/\u0430 \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0436\u0438\u0442\u044c \u0441\u0432\u043e\u0435\u0439 \u0436\u0438\u0437\u043d\u044c\u044e.         for (var i = 0; i &lt; ptrOffset; i++)         {             arrayHeaderPtr[i] = ((nint*) storageHeaderPtr)[i];         }          \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0434\u043b\u0438\u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.         var lengthPtr = (int*) Unsafe.Subtract&lt;nint>(arrayElement0Ptr, 1);         \/\/\u0423\u0441\u0442\u0430\u043d\u0430\u043b\u0438\u0432\u0430\u0435\u043c \u0434\u043b\u0438\u043d\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0437\u0430 \u0432\u044b\u0447\u0435\u0442\u043e\u043c \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.         lengthPtr[0] = storage.Length - elementOffset;                  \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432. \u0421\u0435\u0439\u0447\u0430\u0441 \u043e\u043d \u0440\u0430\u0432\u0435\u043d null. \u0418 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 IntPtr.Zero.         var arrayObjPtr = (nint*) Unsafe.AsPointer(ref array);         \/\/\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 null.         arrayObjPtr[0] = (nint) arrayHeaderPtr;     }      public T[] GetArray(int length)     {         \/\/\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u0434\u043b\u0438\u043d\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u043c.         if (length == array.Length) return array;                  \/\/\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u0435\u043c\u043a\u043e\u0441\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0434 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435,         \/\/\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430.         if (length > storage.Length - elementOffset)         {             \/\/Array.Resize \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u0451\u043c\u043a\u043e\u0441\u0442\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c\u0430\u044f \u0434\u043b\u0438\u043d\u0430 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0443\u044e \u0451\u043c\u043a\u043e\u0441\u0442\u044c.             \/\/\u042d\u0442\u0430 \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u043e\u0433\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043a \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u044f\u043c \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435.             Array.Resize(ref storage, length + elementOffset);                          \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430.             var storageElement0Ptr = Unsafe.AsPointer(ref storage[0]);             \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.             var arrayElement0Ptr = Unsafe.Add&lt;T>(storageElement0Ptr, elementOffset);             \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0430.             var arrayHeaderPtr = Unsafe.Subtract&lt;nint>(arrayElement0Ptr, ptrOffset);             \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432.             var arrayObjPtr = (nint*) Unsafe.AsPointer(ref array);              \/\/\u0420\u0430\u0437\u043c\u0435\u0440 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0431\u044b\u043b \u0438\u0437\u043c\u0435\u043d\u0451\u043d,             \/\/\u043d\u0430\u0448 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0435\u0439\u0447\u0430\u0441 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0440\u044b\u0439 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438.             \/\/\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0430.             \/\/\u0421\u0442\u0430\u0440\u044b\u0439 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u043e\u0447\u0438\u0449\u0435\u043d \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u043e\u043c \u043c\u0443\u0441\u043e\u0440\u0430             \/\/\u043d\u0430 \u043d\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0441\u0441\u044b\u043b\u0430\u0435\u0442\u0441\u044f \u043d\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u043d\u0438 \u043d\u0430\u0448 \u043c\u0430\u0441\u0441\u0438\u0432.             arrayObjPtr[0] = (nint) arrayHeaderPtr;         }                  {             \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.             var arrayElement0Ptr = Unsafe.AsPointer(ref array[0]);             \/\/\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0443\u0447\u0430\u0441\u0442\u043e\u043a \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0434\u043b\u0438\u043d\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.             var lengthPtr = (int*) Unsafe.Subtract&lt;IntPtr>(arrayElement0Ptr, 1);             \/\/\u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0434\u043b\u0438\u043d\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430.             lengthPtr[0] = length;         }                  return array;     } } #pragma warning restore CS8618 #pragma warning restore CS8601<\/code><\/pre>\n<p>\u042f \u043d\u0435 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u043b \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 32 \u0431\u0438\u0442\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0445\u0438\u0442\u0440\u044b\u0445 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0432\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432\u043d\u0443\u0442\u0440\u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0431\u0435\u0437 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043d\u0430 \u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0443\u0441\u043e\u0440\u0430.<\/p>\n<\/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\/post\/715020\/\"> https:\/\/habr.com\/ru\/post\/715020\/<\/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-345030","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/345030","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=345030"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/345030\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=345030"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=345030"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=345030"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}