{"id":265926,"date":"2015-09-18T14:15:02","date_gmt":"2015-09-18T10:15:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=265926"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=265926","title":{"rendered":"\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435"},"content":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/d77\/ff7\/29a\/d77ff729a2b743ba9f312ce22705bae8.jpg\" alt=\"image\"\/><\/p>\n<h4>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h4>\n<p>  \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u0438\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0440\u0435\u0448\u0438\u0442\u044c: \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445, \u0440\u0435\u0437\u043a\u043e \u0443\u043f\u0430\u043b\u0430 \u043f\u043e\u0441\u043b\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 Windows XP\/2003. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Process Explorer \u044f \u0432\u044b\u044f\u0441\u043d\u0438\u043b, \u0447\u0442\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e 1 \u043f\u043e\u0442\u043e\u043a, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0438, \u043f\u0440\u0438\u0447\u0451\u043c TID \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u041d\u0430 \u043b\u0438\u0446\u043e \u044f\u0432\u043d\u0430\u044f \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u044f \u0437\u0430 \u0440\u0435\u0441\u0443\u0440\u0441, \u0438 \u044d\u0442\u0438\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043a\u0443\u0447\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e (default heap). \u041d\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435\/\u0432\u044b\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 (\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\/\u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f STL \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430), \u0447\u0442\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043a \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<h4>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438<\/h4>\n<p>  \u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e (default allocator) \u0434\u043b\u044f STL \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 \u0438 std::basic_string (std::allocator) \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0438\u0437 \u043a\u0443\u0447\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f\/\u0432\u044b\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043d\u0435\u0439 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438 (<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa366597%28v=vs.85%29.aspx\">\u043a\u043e\u0441\u0432\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435<\/a>). \u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u044d\u0442\u043e\u0433\u043e, \u043f\u0440\u0438 \u0447\u0430\u0441\u0442\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445 HeapAlloc\/HeapFree \u043c\u044b \u0440\u0438\u0441\u043a\u0443\u0435\u043c \u043d\u0430\u043c\u0435\u0440\u0442\u0432\u043e \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0443\u0447\u0443 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0432 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435.<\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u041f\u0440\u043e\u0441\u0442\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u041f\u0435\u0440\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u2014 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa366750%28v=vs.85%29.aspx\">low fragmentation heap<\/a>. \u041f\u0440\u0438 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043a\u0443\u0447\u0438 \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u0445\u043e\u0434 \u043f\u0430\u043c\u044f\u0442\u0438 \u0437\u0430 \u0441\u0447\u0451\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u0430, \u0447\u0435\u043c \u0431\u044b\u043b \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d, \u043d\u043e \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u0449\u0435\u0435 \u0431\u044b\u0441\u0442\u0440\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043a\u0443\u0447\u0438. \u0414\u0430\u043d\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u0432 Windows Vista \u0438 \u043d\u043e\u0432\u0435\u0435 (\u043f\u0440\u0430\u0432\u0434\u043e\u043f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0442\u043e\u0440\u043c\u043e\u0437\u043e\u0432 \u043d\u0430 XP\/2003 \u0438 \u0438\u0445 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u044f \u043d\u0430 2008\/7\/2008R2). \u041a\u043e\u0434 \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u0443\u0447\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u0440\u0435\u0436\u0438\u043c \u043f\u0440\u0435\u0434\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442:<\/p>\n<pre><code class=\"cpp\">#define HEAP_LFH 2 ULONG HeapInformation = HEAP_LFH; HeapSetInformation(GetProcessHeap(),  HeapCompatibilityInformation, &HeapInformation, sizeof(HeapInformation)); <\/code><\/pre>\n<p>  \u041f\u043e\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u0438 \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e visual studio 2013 \u043a\u043e\u0434 \u0441\u0434\u0435\u043b\u0430\u043b \u0441\u0432\u043e\u0451 \u0434\u0435\u043b\u043e \u2014 CPU \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d \u043d\u0430 100%, \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u043e\u0441\u044c \u0432 N \u0440\u0430\u0437! \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u0441\u0431\u043e\u0440\u043a\u0435 \u043d\u0430 \u043d\u0430\u0448\u0435\u0439 (\u043c\u043d\u0435 \u0431\u043e\u043b\u044c\u043d\u043e \u044d\u0442\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c&#8230;) visual studio 2003 (\u0434\u0430, \u0435\u0439 \u0435\u0449\u0451 \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f) \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u043e\u0442 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f 0\u2026 \u0425\u044c\u044e\u0441\u0442\u043e\u043d, \u0443 \u043d\u0430\u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b\u2026 <\/p>\n<h4>\u0423\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435<\/h4>\n<p>  \u0412\u0442\u043e\u0440\u043e\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u2014 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u043f\u043e\u0442\u043e\u043a\u0443 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0443\u044e \u043a\u0443\u0447\u0443. \u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c.<\/p>\n<p>  \u0414\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0445\u0435\u043d\u0434\u043b\u043e\u0432 (handle) \u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u0443\u0447 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/ms686749%28v=vs.85%29.aspx\">TLS \u0441\u043b\u043e\u0442\u044b<\/a>. \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u043e\u0439 \u043a\u043e\u0434 \u2014 \u043b\u0438\u0448\u044c \u0447\u0430\u0441\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0439 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c\/\u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u0443 \u043c\u0435\u043d\u044f \u043d\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043a\u0443\u0447\u0443 (\u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u0432\u0441\u0451 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e, \u0441 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435\u043c \u2014 \u0441\u043b\u043e\u0436\u043d\u0435\u0435). \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0443\u043b \u043a\u0443\u0447 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0432\u0438\u0434\u0430:<\/p>\n<pre><code class=\"cpp\">class HeapPool { private:     std::stack&lt;HANDLE&gt; pool;     CRITICAL_SECTION   sync;     bool isOlderNt6; public:     HeapPool()     {         InitializeCriticalSection(&sync);         DWORD dwMajorVersion = (DWORD)(GetVersion() & 0xFF);         isOlderNt6 = (dwMajorVersion &lt; 6);      }      ~HeapPool()     {         DeleteCriticalSection(&sync);         while (!pool.empty()) \/\/ \u0443\u0434\u0430\u043b\u044f\u0435\u043c \u0432\u0441\u0435 \u043a\u0443\u0447\u0438 \u043f\u0440\u0438 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438         {             HeapDestroy(pool.top());             pool.pop();         }     }      HANDLE GetHeap()     {         EnterCriticalSection(&sync);         HANDLE hHeap = NULL;         if (pool.empty())         {             hHeap = HeapCreate(0, 0x100000, 0);             if (isOlderNt6) \/\/ \u0434\u043b\u044f NT6.0+ \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430             {                 ULONG info = 2 \/* HEAP_LFH *\/;                 HeapSetInformation(hHeap, HeapCompatibilityInformation, &info, sizeof(info));             }         }         else         {             hHeap = pool.top();             pool.pop();         }         LeaveCriticalSection(&sync);          return hHeap;     }      void PushHeap(HANDLE hHeap)     {         EnterCriticalSection(&sync);         pool.push(hHeap);         LeaveCriticalSection(&sync);     } };  HeapPool heapPool; \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0443\u043b <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e-\u0441\u043b\u043e\u0442:<\/p>\n<pre><code class=\"cpp\">class TlsHeapSlot { private:     DWORD index; public:     TlsHeapSlot()     {        index = TlsAlloc();     }     void set(HANDLE hHeap)     {         TlsSetValue(index, hHeap);     }     HANDLE get()     {         return (HANDLE)TlsGetValue(index);     } };  \/*\u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u043e\u0434\u043d\u0430\u043a\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u0435\u0442\u043e\u0434\u0430 get() \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043f\u043e\u0442\u043e\u043a\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d \u0432\u044b\u0437\u0432\u0430\u043d *\/ TlsHeapSlot heapSlot;  <\/code><\/pre>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c \u2014 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b std::basic_string \u0438 STL \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432, \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u00ab\u0441\u0430\u043c\u043e\u043f\u0430\u043b\u044c\u043d\u044b\u0439\u00bb \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440:<\/p>\n<pre><code class=\"cpp\">template &lt;typename T&gt; class parallel_allocator : public std::allocator&lt;T&gt; { public:     typedef size_t size_type;     typedef T* pointer;     typedef const T* const_pointer;      template&lt;typename _Tp1&gt;     struct rebind     {         typedef parallel_allocator&lt;_Tp1&gt; other;     };      pointer allocate(size_type n, const void *hint = 0)     {         return (pointer)HeapAlloc(heapSlot.get(), 0, sizeof(T) * n);     }      void deallocate(pointer p, size_type n)     {         HeapFree(heapSlot.get(), 0, p);     }      parallel_allocator() throw() : std::allocator&lt;T&gt;() {}     parallel_allocator(const parallel_allocator &a) throw() : std::allocator&lt;T&gt;(a) { }     template &lt;class U&gt;     parallel_allocator(const parallel_allocator&lt;U&gt; &a) throw() : std::allocator&lt;T&gt;(a) { }     ~parallel_allocator() throw() { } };  <\/code><\/pre>\n<p>  \u0418 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0448\u0442\u0440\u0438\u0445:<\/p>\n<pre><code class=\"cpp\">class HeapWatch \/\/ \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u043a\u0443\u0447\u0438 \u0432 \u043f\u0443\u043b \u043f\u0440\u0438 \u0432\u044b\u0445\u043e\u0434\u0435 { private:     HANDLE hHeap; public:     HeapWatch(HANDLE heap) : hHeap(heap) {}     ~HeapWatch()     {        heapPool.PushHeap(hHeap);     } };   extern &quot;C&quot; int my_api(const char * arg) \/\/ \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0442\u0430\u043a\u043e\u0439 {     HANDLE hHeap = heapPool.GetHeap();     HeapWatch watch(hHeap);     heapSlot.set(hHeap);      \/* \u0417\u0434\u0435\u0441\u044c \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u0438\u043b\u0438 \u043e\u0442\u0441\u044e\u0434\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u0434, \u0438\u043d\u0442\u0435\u043d\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439\/\u0432\u044b\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u044e\u0449\u0438\u0439 \u043f\u0430\u043c\u044f\u0442\u044c.        \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0432\u0440\u043e\u0434\u0435         std::basic_string&lt;char, std::char_traits&lt;char&gt;, parallel_allocator&lt;char&gt; &gt; str \u0438         std::list&lt;int, parallel_allocator&lt;int&gt; &gt; lst,        \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438 \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u043c (\u043f\u0440\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438)     *\/ } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b:<\/h4>\n<p>  \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u0437\u0430\u0434\u0430\u0447\u0430 \u0440\u0435\u0448\u0435\u043d\u0430, \u0438 \u043f\u0440\u0438\u0442\u043e\u043c \u043d\u0435 \u043a\u043e\u0441\u0442\u044b\u043b\u044c\u043d\u043e. \u0412\u0442\u043e\u0440\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0436\u043d\u0435\u0435, \u043d\u043e \u0434\u0430\u0451\u0442 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0430 \u0432\u0441\u0435\u0445 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u0445 (win xp \u2014 windows 10) \u043f\u0440\u0438 \u0441\u0431\u043e\u0440\u043a\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0438 \u0432 VS2013, \u0438 \u0432 VS2003 (\u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u0432 XP\/2003 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 VS 2003 \u2014 \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0447\u0442\u0438 \u0432 N \u0440\u0430\u0437 (\u0433\u0434\u0435 N \u2014 \u0447\u0438\u0441\u043b\u043e \u044f\u0434\u0435\u0440 CPU), \u043d\u0430 \u0431\u043e\u043b\u0435\u0435 \u043d\u043e\u0432\u044b\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0430\u0445 \u2014 \u043e\u0442 3 \u0434\u043e 10 \u043f\u0440\u043e\u0446\u0435\u043d\u0442\u043e\u0432). \u041f\u0440\u043e\u0441\u0442\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u043e\u0439\u0434\u0451\u0442 \u0442\u0435\u043c, \u043a\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0432\u0435\u0436\u0438\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u0432. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0434\u0430\u043d\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043d\u0435.       <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/267155\/\"> http:\/\/habrahabr.ru\/post\/267155\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/d77\/ff7\/29a\/d77ff729a2b743ba9f312ce22705bae8.jpg\" alt=\"image\"\/><\/p>\n<h4>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435<\/h4>\n<p>  \u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0432\u044b\u0440\u043e\u0441\u043b\u0430 \u0438\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0440\u0435\u0448\u0438\u0442\u044c: \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430, \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u0430\u0445, \u0440\u0435\u0437\u043a\u043e \u0443\u043f\u0430\u043b\u0430 \u043f\u043e\u0441\u043b\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 Windows XP\/2003. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Process Explorer \u044f \u0432\u044b\u044f\u0441\u043d\u0438\u043b, \u0447\u0442\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e 1 \u043f\u043e\u0442\u043e\u043a, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0438, \u043f\u0440\u0438\u0447\u0451\u043c TID \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f. \u041d\u0430 \u043b\u0438\u0446\u043e \u044f\u0432\u043d\u0430\u044f \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0446\u0438\u044f \u0437\u0430 \u0440\u0435\u0441\u0443\u0440\u0441, \u0438 \u044d\u0442\u0438\u043c \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u043c \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043a\u0443\u0447\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e (default heap). \u041d\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 \u0430\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435\/\u0432\u044b\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 (\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a, \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\/\u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f STL \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430), \u0447\u0442\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u043a \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044e \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<h4>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438<\/h4>\n<p>  \u041a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e (default allocator) \u0434\u043b\u044f STL \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 \u0438 std::basic_string (std::allocator) \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0438\u0437 \u043a\u0443\u0447\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f\/\u0432\u044b\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043d\u0435\u0439 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0438\u043c\u0438 (<a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa366597%28v=vs.85%29.aspx\">\u043a\u043e\u0441\u0432\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435<\/a>). \u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u044d\u0442\u043e\u0433\u043e, \u043f\u0440\u0438 \u0447\u0430\u0441\u0442\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430\u0445 HeapAlloc\/HeapFree \u043c\u044b \u0440\u0438\u0441\u043a\u0443\u0435\u043c \u043d\u0430\u043c\u0435\u0440\u0442\u0432\u043e \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0443\u0447\u0443 \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0432 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435.<\/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-265926","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/265926","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=265926"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/265926\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=265926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=265926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=265926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}