{"id":185662,"date":"2013-07-05T17:52:02","date_gmt":"2013-07-05T13:52:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=185662"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=185662","title":{"rendered":"<span class=\"post_title\">[C++] \u0412\u0441\u0451 \u043b\u0438 \u043c\u044b \u0437\u043d\u0430\u0435\u043c \u043e\u0431 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u0445 new \u0438 delete?<\/span>"},"content":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041f\u0440\u0438\u0432\u0435\u0442! \u041d\u0438\u0436\u0435 \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e\u0431 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0432\u0441\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u0445 <i>new<\/i> \u0438 <i>delete<\/i>, \u0442\u043e\u0447\u043d\u0435\u0435 \u043e \u0442\u043e\u043c, \u043e \u0447\u0435\u043c \u043d\u0435 \u043f\u0438\u0448\u0443\u0442 \u0432 \u043a\u043d\u0438\u0433\u0430\u0445.<br \/>  \u041d\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u0435\u043d\u044f \u043f\u043e\u0431\u0443\u0434\u0438\u043b\u043e \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u043c\u043e\u0435 \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 <i>new <\/i>\u0438 <i>delete<\/i>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u044f \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432\u0438\u0436\u0443 \u043d\u0430 \u0444\u043e\u0440\u0443\u043c\u0430\u0445 \u0438 \u0434\u0430\u0436\u0435(!!!) \u0432 \u043a\u043d\u0438\u0433\u0430\u0445 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445.<br \/>  \u0412\u0441\u0435 \u043b\u0438 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 <i>new<\/i> \u0438 <i>delete<\/i>? \u0418\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0443\u043c\u0430\u0435\u043c, \u0447\u0442\u043e \u0437\u043d\u0430\u0435\u043c? <br \/>  \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c (\u043d\u0443, \u0430 \u0442\u0435, \u043a\u0442\u043e \u0437\u043d\u0430\u044e\u0442, \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043a\u0440\u0438\u0442\u0438\u043a\u043e\u0432\u0430\u0442\u044c:))<br \/>  <a name=\"habracut\"><\/a><br \/>  <i><b>Note<\/b>: \u043d\u0438\u0436\u0435 \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c \u0438\u0441\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u0431 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0435 new, \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u043e\u0440\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 new \u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0444\u043e\u0440\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 delete \u0432\u0441\u0435 \u043d\u0438\u0436\u0435\u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0430\u0432\u0434\u043e\u0439 \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438. <\/i><\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0438\u0448\u0443\u0442 \u0432 \u043a\u043d\u0438\u0433\u0430\u0445 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445, \u043a\u043e\u0433\u0434\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 <i>new<\/i> (\u0442\u0435\u043a\u0441\u0442 \u0432\u0437\u044f\u0442 \u00ab\u0441 \u043f\u043e\u0442\u043e\u043b\u043a\u0430\u00bb, \u043d\u043e \u0432\u0446\u0435\u043b\u043e\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u0430\u0432\u0434\u0435):  <\/p>\n<blockquote><p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <i>new<\/i> \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u0443\u044e \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u043e\u043c\u0443 \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u0438, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u044f\u0437\u044b\u043a\u0430 \u0421, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440(\u044b) \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430(\u043e\u0432), \u043f\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0430\u043c\u044f\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0430\u2026 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u0438\u0442\u044c (\u0433\u0434\u0435-\u0442\u043e \u043f\u0438\u0448\u0443\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c) \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <i>new <\/i>\u043f\u043e\u0434 \u0441\u0432\u043e\u0438 \u043d\u0443\u0436\u0434\u044b.<\/p><\/blockquote>\n<p>  \u0418 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0443 (\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e) \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 new, \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a<br \/>  <code>void* operator new (std::size_t size) throw (std::bad_alloc);<\/code><\/p>\n<p>  \u041d\u0430 \u0447\u0442\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435:<br \/>  1. \u041d\u0438\u0433\u0434\u0435 \u043d\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044e\u0442 <i><i>new<\/i><\/i> <i>key-word <\/i>\u044f\u0437\u044b\u043a\u0430 \u0421++ \u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <i>new<\/i>, \u0432\u0435\u0437\u0434\u0435 \u043e \u043d\u0438\u0445 \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043a\u0430\u043a \u043e\u0431 \u043e\u0434\u043d\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438.<br \/>  2. \u0412\u0435\u0437\u0434\u0435 \u043f\u0438\u0448\u0443\u0442, \u0447\u0442\u043e <i>new<\/i> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440(\u044b) \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430(\u043e\u0432).<br \/>  \u0418 \u043f\u0435\u0440\u0432\u043e\u0435 \u0438 \u0432\u0442\u043e\u0440\u043e\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u043d\u044b\u043c \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0435\u043c.<\/p>\n<p>  \u041d\u043e \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043d\u0430\u0434\u0435\u044f\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043d\u0438\u0433\u0438 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445, \u043e\u0431\u0440\u0430\u0442\u0438\u043c\u0441\u044f \u043a \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0443, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043a \u0440\u0430\u0437\u0434\u0435\u043b\u0443 5.3.4 \u0438 \u043a 18.6.1, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0438 \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f (\u0442\u043e\u0447\u043d\u0435\u0435 \u043f\u0440\u0438\u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f) \u0442\u0435\u043c\u0430 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438.  <\/p>\n<blockquote><p><b>5.3.4<\/b><br \/>  The new-expression attempts to create an object of the type-id (8.1) or new-type-id to which it is applied. \/*\u0434\u0430\u043b\u044c\u0448\u0435 \u043d\u0430\u043c \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e*\/<br \/>  <b>18.6.1<\/b><br \/>  void* operator new(std::size_t size) throw(std::bad_alloc);<br \/>  Effects: The allocation function called by a new-expression (5.3.4) to allocate size bytes of<br \/>  storage suitably aligned to represent any object of that size \/*\u0434\u0430\u043b\u044c\u0448\u0435 \u043d\u0430\u043c \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e*\/<\/p><\/blockquote>\n<p>  \u0422\u0443\u0442 \u043c\u044b \u0443\u0436\u0435 \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <i>new<\/i> \u0438\u043c\u0435\u043d\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a <i>expression<\/i>, \u0430 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u043e\u043d \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u043a\u0430\u043a o<i>perator.<\/i> \u0418 \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e 2 \u0440\u0430\u0437\u043d\u044b\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438!<br \/>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0435 \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0438, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u043a\u043e\u0434\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0449\u0435\u0433\u043e new. \u041d\u0443, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u043e \u0432\u0441\u0435 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443.<\/p>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0438\u043c\u0441\u044f \u0441 \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u043b\u043e\u0433\u0438\u0435\u0439 \u2014 \u0434\u0430\u043b\u0435\u0435 \u0438\u043c\u0435\u043d\u0443\u0435\u043c\u044b\u0439 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0435 <i>new-expression<\/i> \u044f \u0431\u0443\u0434\u0443 \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c <i>\u00ab\u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 new\u00bb <\/i> (\u043c\u043d\u0435 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u0435\u0439 \u043d\u0430\u043c \u2014 \u043b\u044e\u0434\u044f\u043c \u0432\u043e\u0441\u043f\u0438\u0442\u0430\u043d\u043d\u044b\u043c \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u043e\u044f\u0437\u044b\u0447\u043d\u043e\u0439 \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0435 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445, \u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u043a\u0430\u043a \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e, \u0447\u0430\u0441\u0442\u043e \u0441\u0442\u0440\u0430\u0434\u0430\u0435\u0442 \u043e\u0442 \u00ab\u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430\u00bb), \u0430 <i>operator new <\/i>\u044f \u0442\u0430\u043a \u0438 \u0431\u0443\u0434\u0443 \u043d\u0430\u0437\u044b\u0432\u0430\u0442\u044c <i>operator new<\/i>.<\/p>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0447\u043d\u0435\u043c: \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440<i> new<\/i> \u2014 \u044d\u0442\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u044f\u0437\u044b\u043a\u0430, \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043a\u0430\u043a <i>if<\/i>, <i>while<\/i> \u0438 \u0442.\u0434. (\u0445\u043e\u0442\u044f <i>if,<\/i> <i>while <\/i>\u0438 \u0442.\u0434. \u0432\u0441\u0435 \u0436\u0435 \u0438\u043c\u0435\u043d\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a <i>statement<\/i>, \u043d\u043e \u043e\u0442\u0431\u0440\u043e\u0441\u0438\u043c \u043b\u0438\u0440\u0438\u043a\u0443) \u0422.\u0435. \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044f \u0435\u0433\u043e \u0432 \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0432\u0443\u044e\u0449\u0438\u0439 \u044d\u0442\u043e\u043c\u0443 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0443. \u0422\u0430\u043a \u0436\u0435 <i>new<\/i> \u2014 \u044d\u0442\u043e \u043e\u0434\u043d\u043e \u0438\u0437 <i>key-words<\/i> \u044f\u0437\u044b\u043a\u0430 \u0421++, \u0447\u0442\u043e \u0435\u0449\u0435 \u0440\u0430\u0437 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442 \u0435\u0433\u043e \u043e\u0431\u0449\u043d\u043e\u0441\u0442\u044c \u0441 <i>if<\/i>&#8216;\u0430\u043c\u0438, <i>for&#8217;<\/i>\u0430\u043c\u0438 \u0438 \u0442.\u043f. \u0410 <i>operator new() <\/i>\u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0434\u043d\u043e\u0438\u043c\u0435\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u044f\u0437\u044b\u043a\u0430 \u0421++, \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c. <b>\u0412\u0410\u0416\u041d\u041e<\/b> \u2014 <i>operator new()<\/i> <b>\u041d\u0415<\/b> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440(\u044b) \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430(\u043e\u0432), \u043f\u043e\u0434 \u043a\u043e\u0442\u043e\u0440\u044b\u0439(\u044b\u0435) \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0430\u043c\u044f\u0442\u044c. \u041e\u043d \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u043d\u0443\u0436\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438 \u0432\u0441\u0435. \u0415\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0441\u0438\u0448\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0430 \u0442\u0430\u043a \u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u043c \u0434\u043b\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0432\u0437\u044f\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0435\u0433\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 (\u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u0442\u0435 \u0441\u0430\u043c\u0438:)).<br \/>  \u0410 \u0432\u043e\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <i>new<\/i> \u043a\u0430\u043a \u0440\u0430\u0437 \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440(\u044b) \u043e\u0431\u044a\u0435\u043a\u0442\u0430(\u043e\u0432). \u0425\u043e\u0442\u044f \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0439 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u043d \u0442\u043e\u0436\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442, \u043f\u0440\u043e\u0441\u0442\u043e, \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044f \u0435\u0433\u043e, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u0434 \u0432\u044b\u0437\u043e\u0432\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430(\u043e\u0432).<\/p>\n<p>  \u0414\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"cpp\">#include &lt;iostream&gt;  class Foo { public:     Foo()      {         std::cout &lt;&lt; &quot;Foo()&quot; &lt;&lt; std::endl;     } };  int main () {     Foo *bar = new Foo; } <\/code><\/pre>\n<p>  \u043f\u043e\u0441\u043b\u0435 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430, \u043a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043d\u043e \u00abFoo()\u00bb. \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u043f\u043e\u0447\u0435\u043c\u0443, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430.<br \/>  (\u043a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c cl, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c \u0432 MSVS 2012, \u0445\u043e\u0442\u044f \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e gcc, \u043d\u043e \u044d\u0442\u043e \u043a \u0434\u0435\u043b\u0443 \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f)  <\/p>\n<pre><code>\/Foo *bar = new Foo; push        1  ; \u0440\u0430\u0437\u043c\u0435\u0440 \u0432 \u0431\u0430\u0439\u0442\u0430\u0445 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Foo call        operator new (02013D4h)  ; \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c operator new pop         ecx  mov         dword ptr [ebp-0E0h],eax  ; \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c, \u0432\u0435\u0440\u043d\u0443\u0432\u0448\u0438\u0439\u0441\u044f \u0438\u0437 new, \u0432 bar and         dword ptr [ebp-4],0   cmp         dword ptr [ebp-0E0h],0  ; \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u043d\u0435 0 \u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u043b\u0441\u044f \u0432 bar je          main+69h (0204990h)  ; \u0435\u0441\u043b\u0438 0, \u0442\u043e \u0443\u0445\u043e\u0434\u0438\u043c \u043e\u0442\u0441\u044e\u0434\u0430 (\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u0438\u0437 main \u0438\u043b\u0438 \u0432 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0432\u0430\u0436\u043d\u043e) mov         ecx,dword ptr [ebp-0E0h]  ; \u043a\u043b\u0430\u0434\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c \u0432 ecx (MSVS \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 this \u0432 ecx(rcx)) call        Foo::Foo (02011DBh)  ; \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 ; \u0434\u0430\u043b\u044c\u0448\u0435 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043d\u044f\u043b, \u0432\u043e\u0442 (\u043f\u043e\u0447\u0442\u0438) \u0430\u043d\u0430\u043b\u043e\u0433 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043d\u0430 \u0441\u0438\u043f\u043e\u0434\u043e\u0431\u043d\u043e\u043c \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434\u0435 (\u0442.\u0435. \u043d\u0435 \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c :))  <\/p>\n<pre><code class=\"cpp\">Foo *bar = operator new (1); \/\/ \u0433\u0434\u0435 1 - \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 bar-&gt;Foo(); \/\/ \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442 \u0432\u0441\u0435, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0432\u044b\u0448\u0435, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e:<br \/>  1. \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 (\u044f\u0437\u044b\u043a\u0430) <i>new<\/i> \u0438 <i>operator new() <\/i> \u2014 \u044d\u0442\u043e \u041d\u0415 \u043e\u0434\u043d\u043e \u0438 \u0442\u043e\u0436\u0435.<br \/>  2. <i>operator new() <\/i> \u041d\u0415 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440(\u044b)<br \/>  3. \u0432\u044b\u0437\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430(\u043e\u0432) \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044f \u0432 \u043a\u043e\u0434\u0435 <i>key-word \u00abnew\u00bb<\/i><\/p>\n<p>  \u0418\u0442\u043e\u0433: \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043c\u043e\u0433\u043b\u0430 \u0432\u0430\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u0440\u0430\u0437\u043d\u0438\u0446\u0443 \u043c\u0435\u0436\u0434\u0443 <i>new <\/i>\u0438 <i>operator new() <\/i>\u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0443\u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u0430 (\u044d\u0442\u0430 \u0440\u0430\u0437\u043d\u0438\u0446\u0430) \u0432\u043e\u043e\u0431\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442, \u0435\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u043d\u0435 \u0437\u043d\u0430\u043b.<\/p>\n<p>  P.S. \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <i>delete<\/i> \u0438 <i>operator delete()<\/i> \u0438\u043c\u0435\u044e\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u044f \u0441\u043a\u0430\u0437\u0430\u043b, \u0447\u0442\u043e \u043d\u0435 \u0431\u0443\u0434\u0443 \u0435\u0433\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c. \u0414\u0443\u043c\u0430\u044e, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u043f\u043e\u043d\u044f\u043b\u0438, \u043f\u043e\u0447\u0435\u043c\u0443 \u0435\u0433\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0438 \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e\u0441\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u044b\u0448\u0435 \u0434\u043b\u044f <i>delete<\/i>. \t\t\t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/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\/185662\/\"> http:\/\/habrahabr.ru\/post\/185662\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\"> \t\t\t\u041f\u0440\u0438\u0432\u0435\u0442! \u041d\u0438\u0436\u0435 \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0435\u0442 \u043e\u0431 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0445 \u0432\u0441\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u0445 <i>new<\/i> \u0438 <i>delete<\/i>, \u0442\u043e\u0447\u043d\u0435\u0435 \u043e \u0442\u043e\u043c, \u043e \u0447\u0435\u043c \u043d\u0435 \u043f\u0438\u0448\u0443\u0442 \u0432 \u043a\u043d\u0438\u0433\u0430\u0445.<br \/>  \u041d\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u0435\u043d\u044f \u043f\u043e\u0431\u0443\u0434\u0438\u043b\u043e \u0447\u0430\u0441\u0442\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u0435\u043c\u043e\u0435 \u0437\u0430\u0431\u043b\u0443\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 <i>new <\/i>\u0438 <i>delete<\/i>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u044f \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u0432\u0438\u0436\u0443 \u043d\u0430 \u0444\u043e\u0440\u0443\u043c\u0430\u0445 \u0438 \u0434\u0430\u0436\u0435(!!!) \u0432 \u043a\u043d\u0438\u0433\u0430\u0445 \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445.<br \/>  \u0412\u0441\u0435 \u043b\u0438 \u043c\u044b \u0437\u043d\u0430\u0435\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 <i>new<\/i> \u0438 <i>delete<\/i>? \u0418\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0443\u043c\u0430\u0435\u043c, \u0447\u0442\u043e \u0437\u043d\u0430\u0435\u043c? <br \/>  \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u043c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u044d\u0442\u0438\u043c (\u043d\u0443, \u0430 \u0442\u0435, \u043a\u0442\u043e \u0437\u043d\u0430\u044e\u0442, \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043a\u0440\u0438\u0442\u0438\u043a\u043e\u0432\u0430\u0442\u044c:))  <\/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-185662","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/185662","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=185662"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/185662\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=185662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=185662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=185662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}