Fandom

武装突袭 Wiki

ArmA 2: Custom Memory Allocator

简体 | 繁體

4,827个页面创建
于此维基上
添加新页面
评论0 Share

您使用了广告屏蔽软件!


Wikia通过广告运营为用户提供免费的服务。我们对用户通过嵌入广告屏蔽软件访问网站进行了使用调整。

如果您使用了广告屏蔽软件,将无法使用我们的服务。请您移除广告屏蔽软件,以确保页面正常加载。

Since Arma 2 Operation Arrowhead build 85869 (1.60 beta) it is possible to provide custom memory allocators for the game.
The memory allocator is a very important component, which significantly affects both performance an stability of the game.
The purpose of this customization is to allow the allocator to be developed independently on the application,
allowing both Bohemia Interactive and community to fix bugs and improve performance without having to modify the core game files.

Default编辑

Default allocator used by engine until build 1.60.87645 is based on Intel TBB 3 (see details about tbb3malloc_bi below)
Default allocator used by engine after build 1.60.87645 is based on Intel TBB 4 (see details about tbb4malloc_bi below)

Specifying a custom allocator编辑

The allocator is a dll placed in a directory named "dll" located next to the game executable. Allocator search order is:

If no allocator dll is found, functions _aligned_malloc/ _aligned_free (using Windows Heap functions) are used as a fallback
note: Windows 7 allocator seems to be quite good, and it may therefore make sense for some users to delete all custom allocators on Windows 7 or newer).

You can select an allocator by via commandline below or deleting other allocators from the \dll\ folder.

Commandline parameter编辑

You can specify a particular allocator from a command line, like:

  • -malloc=tbb3malloc_bi
  • -malloc=tbb4malloc_bi
  • -malloc=jemalloc_bi
  • -malloc=tcmalloc_bi
  • -malloc=nedmalloc_bi

or

  • -malloc=mybestmalloc_bi
  • -malloc=system can be used to force using Windows allocator even when allocator dlls are present

(dll directory and extension are appended automatically, the allocator must not be located in other directory and its name must not contain any dots before the .dll extension)

Dedicated server编辑

You can specify allocator for Windows dedicated server the same way as for client binary, but expected performance gain is minimal, because of low concurrency of the dedicated server code compared to a client.

Linux server uses allocator provided by operating system. There are NO plans to allow its customization.

DLL Interface编辑

The dll interface is as follows:

extern "C" {
  __declspec(dllexport) size_t __stdcall MemTotalCommitted();         // _MemTotalCommitted@0
  __declspec(dllexport) size_t __stdcall MemTotalReserved();          // _MemTotalReserved@0
  __declspec(dllexport) size_t __stdcall MemFlushCache(size_t size);  // _MemFlushCache@4
  __declspec(dllexport) void __stdcall MemFlushCacheAll();            // _MemFlushCacheAll@0
  __declspec(dllexport) size_t __stdcall MemSize(void *mem);          // _MemSize@4
  __declspec(dllexport) void *__stdcall MemAlloc(size_t size);        // _MemAlloc@4
  __declspec(dllexport) void __stdcall MemFree(void *mem);            // _MemFree@4
};

Note: besides of the interface above, if the allocator is performing any per-thread caching, it will typically want to perform a cleanup of per-thread data on DLL_THREAD_DETACH event sent to DllMain function.

MemTotalCommitted() 编辑

Total memory committed by the allocator (should correspond to VirtualAlloc with MEM_COMMIT)

MemTotalReserved() 编辑

Total memory reserved by the allocator (should correspond to VirtualAlloc with MEM_RESERVE)

MemFlushCache(size_t size) 编辑

Try to flush at least "size" bytes of memory from caches and working areas, return how much memory was flushed. Called by game when memory needs to be trimmed to reduce virtual memory use.

MemFlushCacheAll() 编辑

Flush all memory held in caches and working areas. Called by game when memory needs to be trimmed to reduce virtual memory use.

MemSize(void *mem) 编辑

Return allocated size of given memory block.

MemAlloc(size_t size) 编辑

Allocate at least size bytes of memory, return the allocated memory. If the size is 16 B or more, the memory must be 16 B -aligned, so that it is usable to hold SSE data.

MemFree(void *mem) 编辑

Free given memory block.

更多维基

随机维基