{"id":430629,"date":"2024-08-28T21:02:12","date_gmt":"2024-08-28T21:02:12","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=430629"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=430629","title":{"rendered":"<span>\u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432 The Simpsons: Hit &amp; Run 2003<\/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<h2>\u041f\u0440\u0438\u0432\u0435\u0442!<\/h2>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432 \u0438\u0433\u0440\u0435 The Simpsons: Hit &amp; Run 2003.  \u0421\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u0434\u0432\u0443\u0445 \u0447\u0430\u0441\u0442\u0435\u0439, \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0441\u0430\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e, \u0430 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043d\u043e \u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 \u044d\u0442\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<p>\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0438\u0433\u0440\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430\u043c\u0438. \u0410\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 &#8212; \u043a\u043b\u0430\u0441\u0441, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438. \u0422\u043e \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 malloc, \u0441 \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c n-\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u0431\u0430\u0439\u0442 \u043f\u043e\u0434 \u0441\u0432\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0431\u0443\u0434\u0435\u0442  \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0430\u043c\u044f\u0442\u044c.<\/p>\n<h2>\u0427\u0430\u0441\u0442\u044c 1<\/h2>\n<h2>\u0412\u0438\u0434\u044b \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432<\/h2>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u0432\u0438\u0434\u043e\u0432 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 \u0438\u0433\u0440\u0435, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0444\u0430\u0439\u043b\u0435 srrmemory.h. \u0422\u0430\u043c \u043e\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u0432\u0438\u0434\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f (enum):<\/p>\n<pre><code class=\"cpp\">enum GameMemoryAllocator {                                              \/\/      GMA_DEFAULT = RADMEMORY_ALLOC_DEFAULT,     \/\/    0              GMA_TEMP = RADMEMORY_ALLOC_TEMP,           \/\/    1          #ifdef RAD_GAMECUBE                                                 GMA_GC_VMM = RADMEMORY_ALLOC_VMM,          \/\/    2          #endif                                                              GMA_PERSISTENT = 3,                        \/\/    3              GMA_LEVEL,                                 \/\/    4               GMA_LEVEL_MOVIE,                           \/\/    5              GMA_LEVEL_FE,                              \/\/    6              GMA_LEVEL_ZONE,                            \/\/    7              GMA_LEVEL_OTHER,                           \/\/    8              GMA_LEVEL_HUD,                             \/\/    9              GMA_LEVEL_MISSION,                         \/\/    10             GMA_LEVEL_AUDIO,                           \/\/    11             GMA_DEBUG,                                 \/\/    12             GMA_SPECIAL,                               \/\/    13             GMA_MUSIC,                                 \/\/    14             GMA_AUDIO_PERSISTENT,                      \/\/    15             GMA_SMALL_ALLOC,                           \/\/    16 #ifdef RAD_XBOX                                     GMA_XBOX_SOUND_MEMORY,                     \/\/    17            #endif #ifdef USE_CHAR_GAG_HEAP     GMA_CHARS_AND_GAGS, #else     GMA_CHARS_AND_GAGS = GMA_LEVEL_OTHER, #endif     GMA_ANYWHERE_IN_LEVEL = 25,                \/\/    25             GMA_ANYWHERE_IN_FE,                        \/\/    26             GMA_EITHER_OTHER_OR_ZONE,                  \/\/    27           GMA_ALLOCATOR_SEARCH = ALLOCATOR_SEARCH,   \/\/   If you feel like using this one, see an example in FMVPlayer::LoadData     NUM_GAME_MEMORY_ALLOCATORS };<\/code><\/pre>\n<p>\u041f\u043e\u0447\u0442\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u044d\u0442\u043e\u0433\u043e enum \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0441\u0432\u043e\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440, \u043d\u043e \u0434\u043b\u044f GMA_ALLOCATOR_SEARCH, GMA_ANYWHERE_IN_LEVEL , GMA_ANYWHERE_IN_FE \u0438 GMA_EITHER_OTHER_OR_ZONE \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e.<\/p>\n<p>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0430\u043a\u043e\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0434\u043b\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0431\u0443\u0434\u044c \u0442\u043e \u043c\u0443\u0437\u044b\u043a\u0430 (GMA_MUSIC), \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c (GMA_LEVEL) \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 avatar.cpp:<\/p>\n<pre><code class=\"cpp\">        HeapMgr()-&gt;PushHeap (GMA_LEVEL_OTHER);          mpVehicleMappable = new VehicleMappable;         mpVehicleMappable-&gt;AddRef();  #ifdef RAD_PS2         mpVehicleMappableUSB0 = new VehicleMappable;         mpVehicleMappableUSB0-&gt;AddRef();          mpVehicleMappableUSB1 = new VehicleMappable;         mpVehicleMappableUSB1-&gt;AddRef(); #endif                  mpHumanVehicleController = new HumanVehicleController;         mpHumanVehicleController-&gt;AddRef();                  mpInCarCharacterMappable = new InCarCharacterMappable;         mpInCarCharacterMappable-&gt;AddRef();          mpBipedCharacterMappable = new BipedCharacterMappable;         mpBipedCharacterMappable-&gt;AddRef();          mpCameraRelativeCharacterController = new CameraRelativeCharacterController;         mpCameraRelativeCharacterController-&gt;AddRef();          HeapMgr()-&gt;PopHeap (GMA_LEVEL_OTHER);<\/code><\/pre>\n<p>\u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u0438\u0434\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 PushHeap, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0442\u0438\u043f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c. \u0417\u0430\u0442\u0435\u043c \u0438\u0434\u0435\u0442 \u0441\u0430\u043c\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 new. \u0410 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0438\u0434\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 PopHeap, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0442\u0438\u043f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443:<\/p>\n<h2>HeapManager<\/h2>\n<p>HeapManager \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f singleton \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043f\u043e\u0441\u0440\u0435\u0434\u043d\u0438\u043a\u043e\u043c \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0430\u0441\u0441\u043e\u043c HeapStack \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c (HeapManager \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u043e\u043b\u044f\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 HeapStack).  \u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c HeapStack \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0441\u0442\u044d\u043a\u043e\u043c (\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0442\u0438\u043f\u0430 GameMemoryAllocator.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 PushHeap \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 Push \u0443 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 HeapStack, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043b\u0430\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 GameMemoryAllocator \u043d\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0441\u0442\u044d\u043a\u0430.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 PopHeap \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 Pop \u0443 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 HeapStack, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0439\u0441\u044f \u043d\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u0435 \u0441\u0442\u044d\u043a\u0430.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>(*) \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 PrepareHeapsStartup, PrepareHeapsFeSetup, PrepareHeapsInGame \u0438 PrepareHeapsSuperSprint.<\/p>\n<\/div>\n<\/details>\n<h2>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 new<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 new \u0438\u043c\u0435\u0435\u0442 \u0432\u0438\u0434:<\/p>\n<pre><code class=\"cpp\">void* operator new( size_t size ) #ifdef RAD_PS2 #ifndef RAD_MW throw( std::bad_alloc ) \/\/ \u043c\u043e\u0436\u0435\u0442 \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 std::bad_alloc #endif #endif {     if( gMemorySystemInitialized == false )     {         INIT_MEM();     }      void* pMemory;      if (g_NoHeapRoute)     {         pMemory = radMemoryAlloc( 0, size );     }     else     {         GameMemoryAllocator curr = HeapMgr()-&gt;GetCurrentHeap();         pMemory = AllocateThis( curr, size );  #ifdef MEMORYTRACKER_ENABLED         ::radMemoryMonitorIdentifyAllocation (pMemory, HeapMgr()-&gt;GetCurrentGroupID ()); #endif     }       \/\/MEMTRACK_ALLOC( pMemory, size, 0 );      return( pMemory ); }<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 new \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443:<\/p>\n<h2>INIT_MEM<\/h2>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0430\u043a\u0440\u043e\u0441\u0430 INIT_MEM \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430 \u0438\u0433\u0440\u0430. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0445 \u0441\u0445\u043e\u0436\u0438, \u043d\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u043a\u0440\u043e\u0441\u0430 \u0434\u043b\u044f PS2:<\/p>\n<pre><code class=\"cpp\">#define INIT_MEM()  Memory::InitializeMemoryUtilities();PS2Platform::InitializeMemory();<\/code><\/pre>\n<p>Memory::InitializeMemoryUtilities() &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0437\u0430 \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0430\u0441\u0447\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043b-\u0432\u0430 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430  \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 (\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434 PS2):<\/p>\n<pre><code class=\"cpp\">void InitializeMemoryUtilities() {     static bool alreadyCalled = false;     if( alreadyCalled )     {         return;     }     alreadyCalled = true; #ifdef RAD_PS2     \/\/this is the largest amount of memory that is free     g_MaxFreeMemory = GetFreeMemoryProfile(); #endif }<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>(*) \u0421\u0442\u043e\u0438\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u0430\u043c\u044f\u0442\u044c PS2 \u0431\u044b\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0432\u0438\u0434\u0435 \u043a\u0430\u0440\u0442 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<\/div>\n<\/details>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f GetFreeMemoryProfile \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c \u043a\u0430\u0440\u0442\u0430\u043c \u043f\u0430\u043c\u044f\u0442\u0438 PS2 \u0438 \u0440\u0430\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438\u0433\u0440\u044b. <\/p>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043a\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 GetFreeMemoryProfile \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443:<\/p>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"cpp\">    const int size = 256;     void* pointers[ size ];     size_t sizes[ size ];      int index = 0;     int i;     for( i = 0; i &lt; size; i++ )     {         pointers[ i ] = NULL;         sizes[ i ] = 0;     }<\/code><\/pre>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0432\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043d\u0430 256 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0433\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 pointers \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u044e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c \u0437\u0430 \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0430 \u043c\u0430\u0441\u0441\u0438\u0432 sizes \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u043e\u043b-\u0432\u043e  \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u043f\u043e\u0434 \u043a\u0430\u0436\u0434\u0443\u044e \u043a\u0430\u0440\u0442\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u0442 \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0440\u0430\u0441\u0447\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043b-\u0432\u0430 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"cpp\">    do     {         int lo = 0;         int hi = 1024*1024*256;         int pivot;         void* memory = NULL;         do         {             pivot = ( hi + lo ) \/ 2;             if( memory != NULL )             {                 free( memory );                 memory = NULL;             }             memory = malloc( pivot );             if( memory != NULL )             {                 lo = pivot;             }             else             {                 memory = malloc( lo );                 hi = pivot;             }         } while( ( hi - lo ) &gt; 1 );          if( ( memory == NULL ) &amp;&amp; ( retrys &lt; 2 ) )         {             ++retrys;         }         else         {             sizes[ index ] = lo;             pointers[ index ] = memory;             memory = NULL;             ++index;         }     } while( ( pointers[ index - 1 ] != NULL ) &amp;&amp; ( index &lt; size ) );<\/code><\/pre>\n<p>\u0420\u0430\u0441\u0447\u0435\u0442 \u043a\u043e\u043b-\u0432\u0430 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u0435\u0434\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u0432 256 \u041c\u0411 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 (\u0442\u0430\u043a \u043a\u0430\u043a \u0437\u0430 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 malloc \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u043a\u0430\u0440\u0442\u044b \u043f\u0430\u043c\u044f\u0442\u0438) \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430. \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043c\u044b \u0437\u0430\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 lo = 0, hi = 1024*1024*256 (256 \u041c\u0411) \u0438 pivot (\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0430 \u043e\u0442\u0440\u0435\u0437\u043a\u0430 [lo; hi]). \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c pivot \u0431\u0430\u0439\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 malloc \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043d\u0435 \u0432\u0435\u0440\u043d\u0443\u043b\u0430 \u043b\u0438 \u043e\u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 NULL (\u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c pivot \u0431\u0430\u0439\u0442). \u0415\u0441\u043b\u0438 malloc \u0432\u0435\u0440\u043d\u0443\u043b NULL, \u0442\u043e  hi \u0441\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435. \u0418\u043d\u0430\u0447\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043a \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0443 lo. \u0422\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 lo \u0438 hi \u043d\u0435 \u0441\u0431\u043b\u0438\u0437\u044f\u0442\u0441\u044f. \u0412 \u0438\u0442\u043e\u0433\u0435, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 lo \u0435\u0441\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435  \u043a\u043e\u043b-\u0432\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0443 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u043e\u0439 \u043a\u0430\u0440\u0442\u044b \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u0432\u0441\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f lo \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 sizes, \u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c memory \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c lo \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 pointers \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u043d\u0435\u0439  \u0435\u0435 \u043e\u0447\u0438\u0441\u0442\u043a\u0438.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>(*) \u0425\u043e\u0442\u044f \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0434\u043d\u043e\u0439 \u043a\u0430\u0440\u0442\u044b \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b 8 \u041c\u0411, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 The Simpsons Hit &amp; Run \u0437\u0430\u0434\u0430\u043b\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0434\u043d\u043e\u0439 \u043a\u0430\u0440\u0442\u044b \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 256 \u041c\u0411. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0440\u044b\u043d\u043a\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u043a\u0438\u0442\u0430\u0439\u0441\u043a\u0438\u0435 \u043a\u0430\u0440\u0442\u044b \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f PS2 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u043c\u0438 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0447\u0435\u043c 8 \u041c\u0411. \u041a\u0438\u0442\u0430\u0439\u0441\u043a\u0430\u044f \u043a\u0430\u0440\u0442\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043c\u043e\u0433\u043b\u0430 \u0432\u043c\u0435\u0449\u0430\u0442\u044c \u0432 \u0441\u0435\u0431\u044f 256 \u041c\u0411.<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0439 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"cpp\">    size_t total = 0;     for( i = 0; i &lt; size; i++ )     {         total += sizes[ i ];     }<\/code><\/pre>\n<p>\u041e\u0447\u0438\u0441\u0442\u043a\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"cpp\">    for( i = 0; i &lt; size; i++ )     {         void* pointer = pointers[ i ];         if( pointer != NULL )         {             free( pointer );             pointers[ i ] = NULL;         }         else         {             break;         }     }<\/code><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f GetFreeMemoryProfile \u0432\u043e\u0437\u0432\u0449\u0430\u0440\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e total, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438 \u0445\u0440\u0430\u043d\u0438\u0442 \u043a\u043e\u043b-\u0432\u043e \u0431\u0430\u0439\u0442 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>(*) \u0424\u0443\u043d\u043a\u0446\u0438\u044f GetFreeMemoryProfile \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f PS2 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0434\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0442\u043e\u0433\u043e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f WIN32 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f GlobalMemoryStatus, \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438  \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0438 \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438. \u0410 \u0434\u043b\u044f PS2 \u0442\u0430\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435\u0431\u044b\u043b\u043e.<\/p>\n<\/div>\n<\/details>\n<p>PS2Platform::InitializeMemory() &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 radMemoryInitialize, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043f\u0430\u043c\u044f\u0442\u0438 (\u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438 radMemoryInitialize \u0431\u0443\u0434\u0435\u0442  \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d \u043f\u043e\u0437\u0436\u0435).<\/p>\n<h2>g_NoHeapRoute<\/h2>\n<p>g_NoHeapRoute &#8212; \u0431\u0443\u043b\u0435\u0432\u0430\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u043b\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432 (false) \u0438\u043b\u0438 \u043d\u0435\u0442 (true). \u0415\u0441\u043b\u0438 \u044d\u0442\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0440\u0430\u0432\u043d\u0430 true, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f radMemoryAlloc, \u043a\u0443\u0434\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 GMA_DEFAULT \u0438 \u0440\u0430\u0437\u043c\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0431\u0430\u0439\u0442\u0430\u0445.<\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c, \u0435\u0441\u043b\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0430, \u0442\u043e \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u044b \u043a \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0443 GMA_DEFAULT.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0436\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f g_NoHeapRoute \u0440\u0430\u0432\u043d\u0430 false, \u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 AllocateThis, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0442\u0438\u043f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430, \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0439\u0441\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0448\u0438\u043d\u043e\u0439 \u0441\u0442\u044d\u043a\u0430 (HeapStack) , \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043e\u043b-\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043d\u044b\u0445 \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0431\u0430\u0439\u0442.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>(*) \u0424\u0443\u043d\u043a\u0446\u0438\u044f radMemoryAlloc \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u0430\u043a\u0438 \u0438 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0441\u0430\u043c\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430. \u041e\u043d\u0430 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 n-\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u0431\u0430\u0439\u0442 \u0443 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \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.<\/p>\n<\/div>\n<\/details>\n<h2>AllocateThis<\/h2>\n<p>AllocateThis &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 n-\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u0431\u0430\u0439\u0442 \u0443 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \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.<\/p>\n<pre><code class=\"cpp\">inline void* AllocateThis( GameMemoryAllocator allocator, size_t size ) {     void* pMemory = NULL; #ifdef CORRAL_SMALL_ALLOCS     if( size &lt; 201 )     {         if( allocator != GMA_AUDIO_PERSISTENT &amp;&amp; allocator != GMA_PERSISTENT &amp;&amp; allocator != GMA_TEMP)         {             pMemory = radMemoryAlloc( GMA_SMALL_ALLOC, size );         }         else         {              pMemory = radMemoryAlloc( allocator, size );         }     }     else #endif     {         if ( allocator &gt;= GMA_ANYWHERE_IN_LEVEL &amp;&amp; allocator != ALLOCATOR_SEARCH )         {             pMemory = FindFreeMemory( allocator, size );         }         else         {             pMemory = radMemoryAlloc( allocator, size );         }     }      return pMemory; }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0434 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 (allocator &gt;= GMA_ANYWHERE_IN_LEVEL), \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f FindFreeMemory.  \u0418\u043d\u0430\u0447\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f radMemoryAlloc.<\/p>\n<h2>FindFreeMemory<\/h2>\n<p>FindFreeMemory &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0435\u043b\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u0440\u0435\u0434\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432.<\/p>\n<pre><code class=\"cpp\">void* FindFreeMemory( GameMemoryAllocator allocator, size_t size ) {     GameMemoryAllocator* list = NULL;     unsigned int numAvailable = 0;      if ( allocator == GMA_ANYWHERE_IN_LEVEL )     {         list = AVAILABLE_FOR_RENT_IN_LEVEL;         numAvailable = sizeof ( AVAILABLE_FOR_RENT_IN_LEVEL ) \/ sizeof( GameMemoryAllocator );     }     else if ( allocator == GMA_ANYWHERE_IN_FE )     {         list = AVAILABLE_FOR_RENT_IN_FE;         numAvailable = sizeof ( AVAILABLE_FOR_RENT_IN_FE ) \/ sizeof( GameMemoryAllocator );     }     else if ( allocator == GMA_EITHER_OTHER_OR_ZONE )     {         list = AVAILABLE_IN_OTHER_OR_ZONE;         numAvailable = sizeof ( AVAILABLE_IN_OTHER_OR_ZONE ) \/ sizeof( GameMemoryAllocator );            }     else     {         rAssert( false );     }      if ( list != NULL )     {         ::radMemorySetUsableAllocators( (radMemoryAllocator*)list, numAvailable );         void* memory = radMemoryAlloc( ALLOCATOR_SEARCH, size );                return memory;     }      return NULL; }<\/code><\/pre>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u043e\u043b-\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u044d\u0442\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430. \u0414\u0430\u043b\u0435\u0435, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c list \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0442\u0440\u0435\u0445 \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u0432, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445 \u0442\u0438\u043f\u044b \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432  \u0442\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439:<\/p>\n<pre><code class=\"cpp\">static GameMemoryAllocator AVAILABLE_FOR_RENT_IN_LEVEL[] = {     GMA_TEMP,     GMA_LEVEL_ZONE,                            \/\/    7         6     6     GMA_LEVEL_OTHER,                           \/\/    8         7     7     GMA_LEVEL_MISSION,                         \/\/    10        9     9     GMA_LEVEL_HUD                              \/\/    9         8     8 }; static GameMemoryAllocator AVAILABLE_FOR_RENT_IN_FE[] = {     GMA_LEVEL_MOVIE,                           \/\/    5         4     4     GMA_LEVEL_FE,                              \/\/    6         5     5     GMA_LEVEL_AUDIO                            \/\/    11        10    10 }; static GameMemoryAllocator AVAILABLE_IN_OTHER_OR_ZONE[] = {     GMA_LEVEL_OTHER,                           \/\/    8         7     7     GMA_LEVEL_ZONE                             \/\/    7         6     6 };<\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f radMemorySetUsableAllocators, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0449\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0442\u0438\u043f\u0430\u0445 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438, \u0438,  \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f radMemoryAlloc, \u043a\u0443\u0434\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f ALLOCATOR_SEARCH \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0438\u043f\u0430 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430.<\/p>\n<p>(1*) \u041f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 ALLOCATOR_SEARCH \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e radMemoryAlloc \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0442\u0438\u043f\u0430 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430, radMemoryAlloc \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f \u043f\u043e \u0434\u0440\u0443\u0433\u043e\u043c\u0443: \u043e\u043d \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0435 \u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430, \u0430 \u0443 \u0446\u0435\u043b\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430, \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u043d\u0435\u0435 \u0447\u0435\u0440\u0435\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u044e radMemorySetUsableAllocators. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u043d \u0431\u0435\u0440\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0443 \u043e\u0434\u043d\u043e\u0433\u043e (\u0438\u043b\u0438  \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0435\u0441\u043b\u0438 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0443\u0436\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c) \u0438\u0437 \u044d\u0442\u0438\u0445 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>(*) \u041e\u0431\u044b\u0447\u043d\u043e \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e radMemoryAlloc \u0442\u0438\u043f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u0438\u043b\u0438 \u0440\u0430\u0432\u043d\u044b\u0439 GMA_ANYWHERE_IN_LEVEL \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442 \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e, \u043a\u0430\u043a\u043e\u0439 \u0438\u043c\u0435\u043d\u043d\u043e \u0438\u0437 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043e\u0431\u0449\u0435\u0433\u043e \u0442\u0438\u043f\u0430 (AVAILABLE_FOR_RENT_IN_LEVEL, AVAILABLE_FOR_RENT_IN_FE \u0438\u043b\u0438 AVAILABLE_IN_OTHER_OR_ZONE) \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c.<\/p>\n<\/div>\n<\/details>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 1 \u0447\u0430\u0441\u0442\u0438<\/h2>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>(*) \u0412\u043e\u043e\u0431\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0430 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 new, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u0435\u0442 \u0441 HeapManager. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435:  new(GMA_PERSISTENT) HeapManager \u042d\u0442\u0430 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430, \u043a\u043e\u0433\u0434\u0430 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434 \u043e\u0434\u0438\u043d \u043e\u0431\u044a\u0435\u043a\u0442. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 new \u043f\u043e\u0447\u0442\u0438 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 new.<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u0442\u043e\u0433\u043e\u0432\u0443\u044e \u0431\u043b\u043e\u043a-\u0441\u0445\u0435\u043c\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \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\/d80\/981\/6fa\/d809816fa666a232363fa1b6d6030d5d.png\" width=\"1928\" height=\"870\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d80\/981\/6fa\/d809816fa666a232363fa1b6d6030d5d.png\"\/><\/figure>\n<h2>\u0427\u0430\u0441\u0442\u044c 2<\/h2>\n<h2>IRadMemoryAllocator<\/h2>\n<p>IRadMemoryAllocator &#8212; \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0432 \u0438\u0433\u0440\u0435.<\/p>\n<pre><code class=\"cpp\">struct IRadMemoryAllocator : public IRefCount {     virtual void* GetMemory( unsigned int size ) = 0; virtual void  FreeMemory( void* pMemory ) = 0;     virtual bool  CanFreeMemory( void * pMemory ) = 0;      virtual void* GetMemoryAligned( unsigned int size, unsigned int alignment ) = 0; virtual void  FreeMemoryAligned( void * pMemory ) = 0;     virtual bool  CanFreeMemoryAligned( void * pMemory ) = 0;  \/\/ \/\/ Memory statistics \/\/      virtual void GetStatus( unsigned int * totalFreeMemory, unsigned int * largestBlock, unsigned int * numberOfObjects, unsigned int * highWaterMark );      virtual unsigned int GetSize( void ); };<\/code><\/pre>\n<p>\u041a\u0440\u0430\u0442\u043a\u043e \u043f\u0440\u043e\u0431\u0435\u0436\u0438\u043c\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u044b: <\/p>\n<p>GetMemory &#8212; \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u0437 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c. <\/p>\n<p>FreeMemory &#8212; \u043e\u0447\u0438\u0449\u0430\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e. <\/p>\n<p>CanFreeMemory &#8212; \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043a \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0443 (\u043f\u0440\u0438 \u043e\u0447\u0438\u0441\u0442\u043a\u0435 \u043f\u0430\u043c\u044f\u0442\u0438). <\/p>\n<p>GetMemoryAligned &#8212; \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0447\u0442\u043e \u0438 GetMemory, \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0442\u0430\u043a\u0436\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u0435. <\/p>\n<p>FreeMemoryAligned &#8212; \u043e\u0447\u0438\u0449\u0430\u0435\u0442 \u0432\u044b\u0440\u0430\u0432\u043d\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e. <\/p>\n<p>CanFreeMemoryAligned &#8212; \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0447\u0442\u043e \u0438 CanFreeMemory (\u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u043d\u0438\u044f).<\/p>\n<h2>radMemoryInitialize<\/h2>\n<p>radMemoryInitialize &#8212; \u0424\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432 (\u0437\u0430\u0434\u0430\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u044b).<\/p>\n<p>\u0422\u0435\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 radMemoryInitialize:<\/p>\n<pre><code class=\"cpp\">if( g_Initialized )     {         return;     }  #ifdef RAD_GAMECUBE     ::radMemoryPlatInitialize( sizeVMMainMemory, sizeVMARAM ); #else     ::radMemoryPlatInitialize( ); #endif      \/\/This is memory reserved to really bad situations where we need to printf. #ifndef RAD_GAMECUBE     gEmergencyMemory = radMemoryPlatAlloc( 1024 * 32 ); #endif      rAssert( g_Initialized == false );     g_Initialized = true;      g_pRadMemoryAllocator_Malloc = new ( g_MemoryForMalloc ) radMemoryAllocatorMalloc( );      g_AllocatorTreeNode_Root.m_pIRadMemoryAllocator = g_pRadMemoryAllocator_Malloc;     g_AllocatorTreeNode_Root.m_pChildren_Head = NULL;     g_AllocatorTreeNode_Root.m_pSibling_Next = NULL;     g_AllocatorTreeNode_Root.m_pParent = NULL;      for( unsigned int i = 0; i &lt; ALLOCATOR_TABLE_SIZE; i ++ )     {         g_AllocatorTreeNodes[ i ].m_pChildren_Head = NULL;         g_AllocatorTreeNodes[ i ].m_pParent = NULL;         g_AllocatorTreeNodes[ i ].m_pSibling_Next = NULL;         g_AllocatorTreeNodes[ i ].m_pIRadMemoryAllocator = g_pRadMemoryAllocator_Malloc;     }  #ifdef RAD_GAMECUBE     unsigned aramSize = (1024 * 1024 * 16) - sizeVMARAM;     radMemorySpaceInitialize( aramSize );     sVMMDLHeapInitialized = false;      if ((sizeVMMainMemory != 0) &amp;&amp; (sizeVMARAM != 0))     {         bool ok = VMAlloc( 0x7E000000, sizeVMARAM );         rAssert( ok );         vmmHeap = radMemoryCreateDougLeaHeap( (void *)0x7E000000, sizeVMARAM, RADMEMORY_ALLOC_DEFAULT, \"GameCube_VMM\" );         rAssert(vmmHeap != NULL);         radMemoryRegisterAllocator( RADMEMORY_ALLOC_VMM, RADMEMORY_ALLOC_DEFAULT, vmmHeap );         sVMMDLHeapInitialized = true; #ifndef RAD_RELEASE         VMSetLogStatsCallback(&amp;gcnVMMLogStats); #endif     }  #else     radMemorySpaceInitialize( ); #endif      \/\/     \/\/ Initialize static heap     \/\/     \/\/g_StaticHeap.CreateHeap( STATIC_HEAP_SIZE );<\/code><\/pre>\n<p>g_AllocatorTreeNodes &#8212; \u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u0438\u043f\u0430 radMemoryAllocatorTreeNode (\u043a\u043e\u043b-\u0432\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 g_AllocatorTreeNodes \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043a\u043e\u043b-\u0432\u043e\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f  GameMemoryAllocators)<\/p>\n<pre><code class=\"cpp\">struct radMemoryAllocatorTreeNode {     IRadMemoryAllocator        * m_pIRadMemoryAllocator; \/\/ the allocator pointer     radMemoryAllocatorTreeNode * m_pChildren_Head; \/\/ list of sub allocators     radMemoryAllocatorTreeNode * m_pSibling_Next;  \/\/ list pointer used by parent      radMemoryAllocatorTreeNode * m_pParent;        \/\/ optomization                  };<\/code><\/pre>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 radMemoryInitialize \u043c\u0430\u0441\u0441\u0438\u0432 g_AllocatorTreeNodes \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e:<\/p>\n<pre><code class=\"cpp\">    for( unsigned int i = 0; i &lt; ALLOCATOR_TABLE_SIZE; i ++ ) \/\/ ALLOCATOR_TABLE_SIZE = 30     {         g_AllocatorTreeNodes[ i ].m_pChildren_Head = NULL;         g_AllocatorTreeNodes[ i ].m_pParent = NULL;         g_AllocatorTreeNodes[ i ].m_pSibling_Next = NULL;         g_AllocatorTreeNodes[ i ].m_pIRadMemoryAllocator = g_pRadMemoryAllocator_Malloc;     }<\/code><\/pre>\n<p>\u0413\u0434\u0435 g_pRadMemoryAllocator_Malloc \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430 radMemoryAllocatorMalloc (radMemoryAllocatorMalloc \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 IRadMemoryAllocator).<\/p>\n<p>radMemoryAllocatorMalloc &#8212; \u044d\u0442\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430. \u0422\u043e \u0435\u0441\u0442\u044c \u043e\u043d \u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0438\u0442\u043e\u0433\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 malloc.<\/p>\n<h2>radMemoryAlloc<\/h2>\n<p>radMemoryAlloc &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0441\u0430\u043c\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430. \u041e\u043d\u0430 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 n-\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u0431\u0430\u0439\u0442 \u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \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.<\/p>\n<p>\u0422\u0435\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 radMemoryAlloc:<\/p>\n<pre><code class=\"cpp\">#ifdef RAD_PS2     if(     (numberOfBytes&lt;201)         &amp;&amp; gbSmallAllocCreated          &amp;&amp; (allocator != HACK_AUDIO_PERSISTENT)         &amp;&amp; (allocator != HACK_PERSISTENT)         &amp;&amp; (allocator != RADMEMORY_ALLOC_TEMP)         )     {         allocator = HACK_SMALL_ALLOC;     } #endif #if ( defined RAD_XBOX ) || ( defined RAD_GAMECUBE ) || ( defined RAD_MW )     if ( !g_Initialized )     {         MemoryHackCallback();     } #endif     if ( numberOfBytes == 0 )     {         return NULL;     }      rAssert( g_Initialized == true );     rAssert( allocator &lt; ALLOCATOR_TABLE_SIZE || allocator == ALLOCATOR_SEARCH );      #ifdef RAD_XBOX         \/\/rAssert( allocator != 2 );     #endif     void * pMem;      if ( allocator == ALLOCATOR_SEARCH )     {         pMem = radMemoryAllocSearch( numberOfBytes, 0 );     }     else     {         IRadMemoryAllocator * pIRadMemoryAllocator =             g_AllocatorTreeNodes[ allocator ].m_pIRadMemoryAllocator;          pMem = pIRadMemoryAllocator-&gt;GetMemory( numberOfBytes );         ::radMemoryMonitorIdentifyAllocation ( pMem, g_CurrentMemoryIdentification );     }      if (g_MemoryActivityCallback)     {         g_MemoryActivityCallback-&gt;MemoryAllocated( allocator, pMem, numberOfBytes );     }      CheckForOutOfMemory( pMem, numberOfBytes, allocator ); \/\/ \u043b\u043e\u0433\u0438     LEAK_DETECTION_ADD_ALLOCATION( pMem, numberOfBytes, allocator ); \/\/ \u043b\u043e\u0433\u0438     return pMem;<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f ALLOCATOR_SEARCH, \u0442\u043e \u0438\u0437 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 g_AllocatorTreeNodes \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u043f\u043e\u0434 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u043c allocator (pIRadMemoryAllocator), \u0438 \u0443 \u0432\u0437\u044f\u0442\u043e\u0433\u043e pIRadMemoryAllocator \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434 GetMemory, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043d\u0443\u0436\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u043c\u044f\u0442\u0438. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0436\u0435, \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0438\u043f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f ALLOCATOR_SEARCH, \u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f radMemoryAllocSearch, \u0440\u0430\u0431\u043e\u0442\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0439 \u0432 (1*).<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432<\/h2>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432 (\u043a\u0430\u043a \u0438 \u0431\u044b\u043b\u043e \u043e\u0442\u043c\u0435\u0447\u0435\u043d\u043e \u0440\u0430\u043d\u0435\u0435) \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 PrepareHeapsStartup, PrepareHeapsFeSetup, PrepareHeapsInGame \u0438 PrepareHeapsSuperSprint \u043a\u043b\u0430\u0441\u0441\u0430  HeapManager. \u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f CreateHeap (\u0438\u0437 \u0444\u0430\u0439\u043b\u0430 createheap.cpp), \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430.<\/p>\n<h2>IRadMemoryHeap<\/h2>\n<p>\u0412\u0441\u0435 GameMemoryAllocators (\u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440) \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430\u043c\u0438, \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u043c\u0438 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430 IRadMemoryHeap (\u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 Heap, \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u043a\u0443\u0447\u0438 \u043a\u0430\u043a  \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0430\u043c \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e).<\/p>\n<p>IRadMemoryHeap &#8212; \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0430\u043c \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0443 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432,  \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0445 \u043e\u0442 IRadMemoryHeap, \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p>Heap \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0440\u0438 \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u0438: Static Heap, Tracking Heap \u0438 Doug Lea Heap:<\/p>\n<ul>\n<li>\n<p>Static Heap &#8212; \u043e\u0431\u044b\u0447\u043d\u044b\u0439 Pool \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u0434 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u0438 \u043f\u043e\u0442\u043e\u043c \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u043f\u0430\u043c\u044f\u0442\u044c. \u041e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u043d\u0435 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043e (\u0442\u043e \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 FreeMemory \u0432 StaticHeap \u043f\u0443\u0441\u0442\u043e\u0439).<\/p>\n<\/li>\n<li>\n<p>Tracking Heap &#8212; \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 malloc, \u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u043d \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0443 \u0441\u0435\u0431\u044f \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043e\u0447\u0438\u0441\u0442\u043a\u0438. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 StaticHeap \u043c\u043e\u0436\u0435\u0442 \u043e\u0447\u0438\u0449\u0430\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>Doug Lea Heap &#8212; \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 dlmalloc, \u043d\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043e\u043d \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0443 \u0441\u0435\u0431\u044f \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043e\u0447\u0438\u0441\u0442\u043a\u0438. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 StaticHeap \u043c\u043e\u0436\u0435\u0442 \u043e\u0447\u0438\u0449\u0430\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c.<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>(*) dlmalloc \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u0438 \u043f\u043b\u044e\u0441\u044b \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c malloc, \u043d\u043e \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u0435\u0433\u043e \u043f\u043b\u044e\u0441 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f dlmalloc \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b  (\u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 malloc). \u0422\u0430\u043a\u0436\u0435 \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e dlmalloc \u0432\u044b\u0433\u043e\u0434\u043d\u0435\u0435 \u043f\u0440\u0438 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043c\u0430\u043b\u043e\u0433\u043e \u043a\u043e\u043b-\u0432\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 (&lt;= 201 \u0431\u0430\u0439\u0442) \u0447\u0435\u043c malloc.<\/p>\n<\/div>\n<\/details>\n<h2>CreateHeap<\/h2>\n<p>\u0422\u0435\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 CreateHeap:<\/p>\n<pre><code class=\"cpp\">void CreateHeap ( GameMemoryAllocator allocator, const unsigned int size ) {     unsigned int index = static_cast&lt; unsigned int &gt;( allocator );     rAssert( g_HeapArray[ index ] == NULL );      HeapType type    = g_HeapCreationData[ index ].type;     const char* name = g_HeapCreationData[ index ].name;     GameMemoryAllocator parent = g_HeapCreationData[ index ].parent;      rReleasePrintf (\"Creating Heap: %s (%d)\\n\", name, size );      #ifdef RAD_RELEASE     if( type == HEAP_TYPE_TRACKING )     {         type = HEAP_TYPE_NONE;     }     #endif      switch( type )     {         case HEAP_TYPE_STATIC :         {             HeapMgr()-&gt;PushHeap( GMA_DEBUG );             g_HeapArray[ index ] = radMemoryCreateStaticHeap( size, RADMEMORY_ALLOC_DEFAULT, name );             g_HeapArray[ index ]-&gt;AddRef();             HeapMgr()-&gt;PopHeap( GMA_DEBUG );             break;         }         case HEAP_TYPE_TRACKING :         {             HeapMgr()-&gt;PushHeap( GMA_DEBUG );             g_HeapArray[ index ] = radMemoryCreateTrackingHeap( size, RADMEMORY_ALLOC_DEFAULT, name );             HeapMgr()-&gt;PopHeap( GMA_DEBUG );             break;         }         case HEAP_TYPE_DOUG_LEA :         {             HeapMgr()-&gt;PushHeap( GMA_DEBUG );             g_HeapArray[ index ] = radMemoryCreateDougLeaHeap( size, RADMEMORY_ALLOC_DEFAULT, name );             g_HeapArray[ index ]-&gt;AddRef();             HeapMgr()-&gt;PopHeap( GMA_DEBUG );             break;         }         case HEAP_TYPE_NONE :         {             \/\/rAssert( false );             return;         }         default:         {             rAssert( false );             return;         }     }     radMemoryRegisterAllocator( allocator, parent,g_HeapArray[ index ] ); }<\/code><\/pre>\n<p>g_HeapCreationData &#8212; \u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u0438\u043f\u0430 HeapCreationData, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430\u0445, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: \u0442\u0438\u043f, \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c, \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435:<\/p>\n<pre><code class=\"cpp\">struct HeapCreationData {     HeapType            type;     GameMemoryAllocator parent;     char                name[ 256 ]; };  HeapCreationData g_HeapCreationData[] =  {     { HEAP_TYPE_DOUG_LEA, GMA_DEFAULT, \"Default\"              },           { HEAP_TYPE_DOUG_LEA, GMA_DEFAULT, \"Temp\"                 },           { HEAP_TYPE_NONE,     GMA_DEFAULT, \"Gamecube VMM\"         },       #ifdef RAD_WIN32     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Persistent\"           },  \/\/ no static heap for pc #else     { HEAP_TYPE_STATIC,   GMA_DEFAULT, \"Persistent\"           }, #endif \/\/ RAD_WIN32     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Level\"                },     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Level Movie\"          },     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Level FE\"             },     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Level Zone\"           },     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Level Other\"          },     { HEAP_TYPE_DOUG_LEA, GMA_DEFAULT, \"Level Hud\"            },     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Level Mission\"        },     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Level Audio\"          },     { HEAP_TYPE_NONE,     GMA_DEFAULT, \"Debug\"                },     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Special\"              },     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Music\"                },     { HEAP_TYPE_DOUG_LEA, GMA_DEFAULT, \"Audio Persistent\"     },     { HEAP_TYPE_DOUG_LEA, GMA_DEFAULT, \"Small Alloc\"          }, #ifdef RAD_XBOX     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"XBOX Sound\"           }, #endif #ifdef USE_CHAR_GAG_HEAP     { HEAP_TYPE_DOUG_LEA, GMA_DEFAULT, \"Characters and Gags\"  }, #endif     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Anywhere in Level\"    },     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Anywhere in FE\"       },     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Either Other or Zone\" },     { HEAP_TYPE_TRACKING, GMA_DEFAULT, \"Search\"               },     { HEAP_TYPE_NONE,     GMA_DEFAULT, \"???\"                  },     { HEAP_TYPE_NONE,     GMA_DEFAULT, \"???\"                  }, };<\/code><\/pre>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435, \u043f\u043e\u0441\u043b\u0435 \u0441\u0430\u043c\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 radMemoryCreateStaticHeap, radMemoryCreateTrackingHeap \u0438\u043b\u0438 radMemoryCreateDougLeaHeap \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f  radMemoryRegisterAllocator, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440, \u043b\u0435\u0436\u0430\u0449\u0438\u0439 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 allocator \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435 g_AllocatorTreeNodes, \u043d\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043d\u0430\u043c\u0438 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440. <\/p>\n<h2>radMemoryCreateStaticHeap<\/h2>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 Static Heap.<\/p>\n<p>radMemoryCreateStaticHeap &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c Pool \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430.<\/p>\n<p>\u0422\u0435\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 radMemoryCreateStaticHeap:<\/p>\n<pre><code class=\"cpp\">    rReleasePrintf(\"%s \", pName );     StaticHeap* pHeap = new ( allocator ) StaticHeap; \/\/ \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 radMemoryAllocatorMalloc     pHeap-&gt;CreateHeap( size );     return pHeap;<\/code><\/pre>\n<p>\u0422\u0435\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 StaticHeap::CreateHeap:<\/p>\n<pre><code class=\"cpp\">    m_FreeingAllowed = false;     m_TotalAllocations = 0;     m_TotalSize = size;     m_BasePointer = reinterpret_cast&lt; char* &gt;( radMemoryPlatAlloc( size ) );     rAssert( m_BasePointer != NULL );     m_CurrentPointer = m_BasePointer;     m_End = reinterpret_cast&lt; char* &gt;( reinterpret_cast&lt; size_t &gt;( m_BasePointer ) + size );     m_Overflow = 0;      rReleasePrintf(\"StaticHeap Start: 0x%x, End:0x%x\\n\", m_BasePointer, m_End );      #ifdef RADMEMORYMONITOR     {         radMemoryMonitorIdentifyAllocation( (void*)m_BasePointer, g_nameFTech, \"StaticAllocator::m_StartOfMemory\" );         radMemoryMonitorDeclareSection( (void*)m_BasePointer, m_TotalSize, IRadMemoryMonitor::MemorySectionType_DynamicData );         char szName[ 128 ];         sprintf( szName, \"[StaticAllocator]\" );         radMemoryMonitorIdentifySection( (void*)m_BasePointer, szName );     }     #endif \/\/ RADMEMORYMONITOR<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 StaticHeap::CreateHeap \u043f\u0430\u043c\u044f\u0442\u044c \u043f\u043e\u0434 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 radMemoryPlatAlloc, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 malloc  \u0441 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u043f\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0443 g_HeapCreationData, \u0442\u043e\u043b\u044c\u043a\u043e GMA_PERSISTENT \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 StaticHeap. \u0422\u0430\u043a\u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0441\u0430\u043c\u044b\u0435 \u0433\u043b\u0430\u0432\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0432 \u0438\u0433\u0440\u0435  \u0432\u044b\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 GMA_PERSISTENT.<\/p>\n<p>\u041a\u043e\u0434 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 (ps2main.cpp):<\/p>\n<pre><code class=\"cpp\">    HeapMgr()-&gt;PushHeap (GMA_PERSISTENT);  \/\/Process any commandline options from the command.txt file ProcessCommandLineArgumentsFromFile();      \/\/     \/\/ Instantiate all the singletons before doing anything else.     \/\/     CreateSingletons();      \/\/     \/\/ Construct the platform object.     \/\/     PS2Platform* pPlatform = PS2Platform::CreateInstance();     rAssert( pPlatform != NULL );      \/\/     \/\/ Create the game object.     \/\/     Game* pGame = Game::CreateInstance( pPlatform );     rAssert( pGame != NULL );      \/\/     \/\/ Initialize the game.     \/\/     pGame-&gt;Initialize();      HeapMgr()-&gt;PopHeap (GMA_PERSISTENT);<\/code><\/pre>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 GMA_PERSISTENT \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u0438\u0435\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u0442\u044f\u0436\u0435\u043b\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 GMA_PERSISTENT \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c \u0442\u0435 \u0436\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u0434\u0440\u0443\u0433\u0438\u0435 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u044b.<\/p>\n<\/div>\n<\/details>\n<h2>\u0412\u044b\u0432\u043e\u0434<\/h2>\n<p>\u0414\u043b\u044f \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0434 \u0442\u044f\u0436\u0435\u043b\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Static Heap (GMA_PERSISTENT), \u043f\u043e\u0434 \u043b\u0435\u0433\u043a\u0438\u0435 Doug Lea Heap, \u0430 \u043f\u043e\u0434 \u0441\u0440\u0435\u0434\u043d\u0438\u0435 Tracking Heap.<\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u044b\u043b\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430 \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u043c\u043e\u0434\u043e\u0434\u0435\u043b\u0430\u043c \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u043e\u0445\u043e\u0436\u0438\u043c.<\/p>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0438\u0433\u0440\u044b The Simpsons: Hit &amp; Run 2003 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0437\u0434\u0435\u0441\u044c:<\/p>\n<div class=\"embed_link\">\n<div class=\"embed__thumb\" style=\"background-image: url(&quot;https:\/\/opengraph.githubassets.com\/afc3204d6689895edc4fd2dbbdc7a64a674bacbb64db62f19c9def8bae787f65\/FlexodMR\/Simpsons&quot;);\"><\/div>\n<div class=\"embed__caption\">\n<div class=\"embed__caption-title\"><span>GitHub &#8212; FlexodMR\/Simpsons: Original source for &#171;The Simpsons: Hit &amp; Run&#187; game<\/span><\/div>\n<p><a href=\"https:\/\/github.com\/FlexodMR\/Simpsons\" target=\"_blank\" rel=\"noopener noreferrer nofollow\" class=\"embed__caption-link\">github.com<\/a><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/839380\/\"> https:\/\/habr.com\/ru\/articles\/839380\/<\/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<h2>\u041f\u0440\u0438\u0432\u0435\u0442!<\/h2>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432 \u0438\u0433\u0440\u0435 The Simpsons: Hit &amp; Run 2003.  \u0421\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u0442\u044c \u0438\u0437 \u0434\u0432\u0443\u0445 \u0447\u0430\u0441\u0442\u0435\u0439, \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u0441\u0430\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e, \u0430 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043d\u043e \u043e \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 \u044d\u0442\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b.<\/p>\n<p>\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0438\u0433\u0440\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430\u043c\u0438. \u0410\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 &#8212; \u043a\u043b\u0430\u0441\u0441, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438. \u0422\u043e \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 malloc, \u0441 \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c n-\u043e\u0435 \u043a\u043e\u043b-\u0432\u043e \u0431\u0430\u0439\u0442 \u043f\u043e\u0434 \u0441\u0432\u043e\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u0438 \u0431\u0443\u0434\u0435\u0442  \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u0430\u043c\u044f\u0442\u044c.<\/p>\n<h2>\u0427\u0430\u0441\u0442\u044c 1<\/h2>\n<h2>\u0412\u0438\u0434\u044b \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432<\/h2>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u0432\u0438\u0434\u043e\u0432 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 \u0438\u0433\u0440\u0435, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0444\u0430\u0439\u043b\u0435 srrmemory.h. \u0422\u0430\u043c \u043e\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u0432\u0438\u0434\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f (enum):<\/p>\n<pre><code class=\"cpp\">enum GameMemoryAllocator {                                              \/\/      GMA_DEFAULT = RADMEMORY_ALLOC_DEFAULT,     \/\/    0              GMA_TEMP = RADMEMORY_ALLOC_TEMP,           \/\/    1          #ifdef RAD_GAMECUBE                                                 GMA_GC_VMM = RADMEMORY_ALLOC_VMM,          \/\/    2          #endif                                                              GMA_PERSISTENT = 3,                        \/\/    3              GMA_LEVEL,                                 \/\/    4               GMA_LEVEL_MOVIE,                           \/\/    5              GMA_LEVEL_FE,                              \/\/    6              GMA_LEVEL_ZONE,                            \/\/    7              GMA_LEVEL_OTHER,                           \/\/    8              GMA_LEVEL_HUD,                             \/\/    9              GMA_LEVEL_MISSION,                         \/\/    10             GMA_LEVEL_AUDIO,                           \/\/    11             GMA_DEBUG,                                 \/\/    12             GMA_SPECIAL,                               \/\/    13             GMA_MUSIC,                                 \/\/    14             GMA_AUDIO_PERSISTENT,                      \/\/    15             GMA_SMALL_ALLOC,                           \/\/    16 #ifdef RAD_XBOX                                     GMA_XBOX_SOUND_MEMORY,                     \/\/    17            #endif #ifdef USE_CHAR_GAG_HEAP     GMA_CHARS_AND_GAGS, #else     GMA_CHARS_AND_GAGS = GMA_LEVEL_OTHER, #endif     GMA_ANYWHERE_IN_LEVEL = 25,                \/\/    25             GMA_ANYWHERE_IN_FE,                        \/\/    26             GMA_EITHER_OTHER_OR_ZONE,                  \/\/    27           GMA_ALLOCATOR_SEARCH = ALLOCATOR_SEARCH,   \/\/   If you feel like using this one, see an example in FMVPlayer::LoadData     NUM_GAME_MEMORY_ALLOCATORS };<\/code><\/pre>\n<p>\u041f\u043e\u0447\u0442\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u044d\u0442\u043e\u0433\u043e enum \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0441\u0432\u043e\u0439 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440, \u043d\u043e \u0434\u043b\u044f GMA_ALLOCATOR_SEARCH, GMA_ANYWHERE_IN_LEVEL , GMA_ANYWHERE_IN_FE \u0438 GMA_EITHER_OTHER_OR_ZONE \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e.<\/p>\n<p>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0430\u043a\u043e\u0439 \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0434\u043b\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0431\u0443\u0434\u044c \u0442\u043e \u043c\u0443\u0437\u044b\u043a\u0430 (GMA_MUSIC), \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u0430\u044f \u0441 \u0443\u0440\u043e\u0432\u043d\u0435\u043c (GMA_LEVEL) \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435.<\/p>\n<h2>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u044c\u044e \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 avatar.cpp:<\/p>\n<pre><code class=\"cpp\">        HeapMgr()-&gt;PushHeap (GMA_LEVEL_OTHER);          mpVehicleMappable = new VehicleMappable;         mpVehicleMappable-&gt;AddRef();  #ifdef RAD_PS2         mpVehicleMappableUSB0 = new VehicleMappable;         mpVehicleMappableUSB0-&gt;AddRef();          mpVehicleMappableUSB1 = new VehicleMappable;         mpVehicleMappableUSB1-&gt;AddRef(); #endif                  mpHumanVehicleController = new HumanVehicleController;         mpHumanVehicleController-&gt;AddRef();                  mpInCarCharacterMappable = new InCarCharacterMappable;         mpInCarCharacterMappable-&gt;AddRef();          mpBipedCharacterMappable = new BipedCharacterMappable;         mpBipedCharacterMappable-&gt;AddRef();          mpCameraRelativeCharacterController = new CameraRelativeCharacterController;         mpCameraRelativeCharacterController-&gt;AddRef();          HeapMgr()-&gt;PopHeap (GMA_LEVEL_OTHER);<\/code><\/pre>\n<p>\u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u0438\u0434\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 PushHeap, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0442\u0438\u043f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c. \u0417\u0430\u0442\u0435\u043c \u0438\u0434\u0435\u0442 \u0441\u0430\u043c\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432 \u043f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 new. \u0410 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0438\u0434\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 PopHeap, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0442\u0438\u043f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u0430, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u043b\u043e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443:<\/p>\n<h2>HeapManager<\/h2>\n<p>HeapManager \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f singleton \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u043f\u043e\u0441\u0440\u0435\u0434\u043d\u0438\u043a\u043e\u043c \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0430\u0441\u0441\u043e\u043c HeapStack \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c (HeapManager \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u043e\u043b\u044f\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 HeapStack).  \u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c HeapStack \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u0441\u0442\u044d\u043a\u043e\u043c (\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0445\u0440\u0430\u043d\u0438\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0442\u0438\u043f\u0430 GameMemoryAllocator.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 PushHeap \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 Push \u0443 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 HeapStack, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043b\u0430\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 GameMemoryAllocator \u043d\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u0443 \u0441\u0442\u044d\u043a\u0430.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 PopHeap \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 Pop \u0443 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 HeapStack, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u0434\u0430\u043b\u044f\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0439\u0441\u044f \u043d\u0430 \u0432\u0435\u0440\u0448\u0438\u043d\u0435 \u0441\u0442\u044d\u043a\u0430.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>(*) \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0430\u043b\u043b\u043e\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 PrepareHeapsStartup, PrepareHeapsFeSetup, PrepareHeapsInGame \u0438 PrepareHeapsSuperSprint.<\/p>\n<\/div>\n<\/details>\n<h2>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 new<\/h2>\n<p>\u041f\u0435\u0440\u0435\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 new \u0438\u043c\u0435\u0435\u0442 \u0432\u0438\u0434:<\/p>\n<pre><code class=\"cpp\">void* operator new( size_t size ) #ifdef RAD_PS2 #ifndef RAD_MW throw( std::bad_alloc ) \/\/ \u043c\u043e\u0436\u0435\u0442 \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 std::bad_alloc #endif #endif {     if( gMemorySystemInitialized == false )     {         INIT_MEM();     }      void* pMemory;      if (g_NoHeapRoute)     {         pMemory = radMemoryAlloc( 0, size );     }     else     {         GameMemoryAllocator curr = HeapMgr()-&gt;GetCurrentHeap();         pMemory = AllocateThis( curr, size );  #ifdef MEMORYTRACKER_ENABLED         ::radMemoryMonitorIdentifyAllocation (pMemory, HeapMgr()-&gt;GetCurrentGroupID ()); #endif     }       \/\/MEMTRACK_ALLOC( pMemory, size, 0 );      return( pMemory ); }<\/code><\/pre>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 new \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443:<\/p>\n<h2>INIT_MEM<\/h2>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0430\u043a\u0440\u043e\u0441\u0430 INIT_MEM \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430 \u0438\u0433\u0440\u0430. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0445 \u0441\u0445\u043e\u0436\u0438, \u043d\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u043a\u0440\u043e\u0441\u0430 \u0434\u043b\u044f PS2:<\/p>\n<pre><code class=\"cpp\">#define INIT_MEM()  Memory::InitializeMemoryUtilities();PS2Platform::InitializeMemory();<\/code><\/pre>\n<p>Memory::InitializeMemoryUtilities() &#8212; \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0437\u0430 \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u0430\u0441\u0447\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043b-\u0432\u0430 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430  \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 (\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0434 PS2):<\/p>\n<pre><code class=\"cpp\">void InitializeMemoryUtilities() {     static bool alreadyCalled = false;     if( alreadyCalled )     {         return;     }     alreadyCalled = true; #ifdef RAD_PS2     \/\/this is the largest amount of memory that is free     g_MaxFreeMemory = GetFreeMemoryProfile(); #endif }<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>(*) \u0421\u0442\u043e\u0438\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c, \u0447\u0442\u043e \u043f\u0430\u043c\u044f\u0442\u044c PS2 \u0431\u044b\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0432 \u0432\u0438\u0434\u0435 \u043a\u0430\u0440\u0442 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<\/div>\n<\/details>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f GetFreeMemoryProfile \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u0432\u0441\u0435\u043c \u043a\u0430\u0440\u0442\u0430\u043c \u043f\u0430\u043c\u044f\u0442\u0438 PS2 \u0438 \u0440\u0430\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0438\u0433\u0440\u044b. <\/p>\n<p>\u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043a\u043e\u0434 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 GetFreeMemoryProfile \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443:<\/p>\n<p>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f:<\/p>\n<pre><code class=\"cpp\">    const int size = 256;     void* pointers[ size ];     size_t sizes[ size ];      int index = 0;     int i;     for( i = 0; i &lt; size; i++ )     {         pointers[ i ] = NULL;         sizes[ i ] = 0;     }<\/code><\/pre>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0432\u0430 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u043d\u0430 256 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0433\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 pointers \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432\u0441\u044e \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c \u0437\u0430 \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0430 \u043c\u0430\u0441\u0441\u0438\u0432 sizes \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043a\u043e\u043b-\u0432\u043e  \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e \u043f\u043e\u0434 \u043a\u0430\u0436\u0434\u0443\u044e \u043a\u0430\u0440\u0442\u0443 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u0442 \u0433\u043b\u0430\u0432\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0440\u0430\u0441\u0447\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043b-\u0432\u0430 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"cpp\">    do     {         int lo = 0;         int hi = 1024*1024*256;         int pivot;         void* memory = NULL;         do         {             pivot = ( hi + lo ) \/ 2;             if( memory != NULL )             {                 free( memory );                 memory = NULL;             }             memory = malloc( pivot );             if( memory != NULL )             {                 lo = pivot;             }             else             {                 memory = malloc( lo );                 hi = pivot;             }         } while( ( hi - lo ) &gt; 1 );          if( ( memory == NULL ) &amp;&amp; ( retrys &lt; 2 ) )         {             ++retrys;         }         else         {             sizes[ index ] = lo;             pointers[ index ] = memory;             memory = NULL;             ++index;         }     } while( ( pointers[ index - 1 ] != NULL ) &amp;&amp; ( index &lt; size ) );<\/code><\/pre>\n<p>\u0420\u0430\u0441\u0447\u0435\u0442 \u043a\u043e\u043b-\u0432\u0430 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432\u0435\u0434\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0431\u043b\u043e\u043a\u0430 \u0432 256 \u041c\u0411 \u043f\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 (\u0442\u0430\u043a \u043a\u0430\u043a \u0437\u0430 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 malloc \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u043a\u0430\u0440\u0442\u044b \u043f\u0430\u043c\u044f\u0442\u0438) \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430. \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043c\u044b \u0437\u0430\u0434\u0430\u0435\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 lo = 0, hi = 1024*1024*256 (256 \u041c\u0411) \u0438 pivot (\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0430 \u043e\u0442\u0440\u0435\u0437\u043a\u0430 [lo; hi]). \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c pivot \u0431\u0430\u0439\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 malloc \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u043d\u0435 \u0432\u0435\u0440\u043d\u0443\u043b\u0430 \u043b\u0438 \u043e\u043d\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 NULL (\u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c pivot \u0431\u0430\u0439\u0442). \u0415\u0441\u043b\u0438 malloc \u0432\u0435\u0440\u043d\u0443\u043b NULL, \u0442\u043e  hi \u0441\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435. \u0418\u043d\u0430\u0447\u0435 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u043a \u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0443 lo. \u0422\u0430\u043a \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u0442\u0435\u0445 \u043f\u043e\u0440, \u043f\u043e\u043a\u0430 lo \u0438 hi \u043d\u0435 \u0441\u0431\u043b\u0438\u0437\u044f\u0442\u0441\u044f. \u0412 \u0438\u0442\u043e\u0433\u0435, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 lo \u0435\u0441\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435  \u043a\u043e\u043b-\u0432\u043e \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0443 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c\u043e\u0439 \u043a\u0430\u0440\u0442\u044b \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u0432\u0441\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f lo \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 sizes, \u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c memory \u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c lo \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 pointers \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u043d\u0435\u0439  \u0435\u0435 \u043e\u0447\u0438\u0441\u0442\u043a\u0438.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442<\/summary>\n<div class=\"spoiler__content\">\n<p>(*) \u0425\u043e\u0442\u044f \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0434\u043d\u043e\u0439 \u043a\u0430\u0440\u0442\u044b \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b 8 \u041c\u0411, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 The Simpsons Hit &amp; Run \u0437\u0430\u0434\u0430\u043b\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0434\u043d\u043e\u0439 \u043a\u0430\u0440\u0442\u044b \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 256 \u041c\u0411. \u042d\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043e \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0440\u044b\u043d\u043a\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u043a\u0438\u0442\u0430\u0439\u0441\u043a\u0438\u0435 \u043a\u0430\u0440\u0442\u044b \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f PS2 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u043c\u0438 \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u0447\u0435\u043c 8 \u041c\u0411. \u041a\u0438\u0442\u0430\u0439\u0441\u043a\u0430\u044f \u043a\u0430\u0440\u0442\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043c\u043e\u0433\u043b\u0430 \u0432\u043c\u0435\u0449\u0430\u0442\u044c \u0432 \u0441\u0435\u0431\u044f 256 \u041c\u0411.<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0443\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u0441\u0435\u0439 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"cpp\">    size_t total = 0;     for( i = 0; i &lt; size; i++ )     {         total += sizes[ i ];     }<\/code><\/pre>\n<p>\u041e\u0447\u0438\u0441\u0442\u043a\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<pre><code class=\"cpp\">    for( i = 0; i &lt; size; i++ )     {         void* pointer = pointers[ i ];         if( pointer != NULL )         {             free( pointer );             pointers[ i ] = NULL;         }         else         {             break;         }     }<\/code><\/pre>\n<p>\u0412<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-430629","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/430629","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=430629"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/430629\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=430629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=430629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=430629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}