Custom Memory Allocator – Arma 2
m (Formatting) |
(Specifying a custom allocator) |
||
Line 1: | Line 1: | ||
[[Category:Arma 2]] [[Category:Arma 2: Editing]] | [[Category:Arma 2]] [[Category:Arma 2: Editing]] | ||
Since Arma 2 Operation Arrowhead build 85869 (1.60 beta) it is possible to provide custom memory allocators for the game | Since Arma 2 Operation Arrowhead build 85869 (1.60 beta) it is possible to provide custom memory allocators for the game. | ||
==DLL Interface== | ==DLL Interface== | ||
Line 37: | Line 37: | ||
=== MemFree(void *mem) === | === MemFree(void *mem) === | ||
Free given memory block. | Free given memory block. | ||
==Specifying a custom allocator== | |||
The allocator is a dll placed in dll directory located next to the game executable. Allocator search order is: | |||
* tbb3malloc_bi - based on [http://threadingbuildingblocks.org/ver.php?fid=171 Intel TBB 3], distributed under [http://www.gnu.org/licenses/gpl-2.0.html GPL v2] + [http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt01ch01s02.html RE] | |||
* tbb4malloc_bi - based on [http://threadingbuildingblocks.org/ver.php?fid=176 Intel TBB 4], distributed under [http://www.gnu.org/licenses/gpl-2.0.html GPL v2] + [http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt01ch01s02.html RE] | |||
* jemalloc_bi - not available yet, based on [http://www.canonware.com/download/jemalloc/ JEMalloc], distributed under [http://www.canonware.com/jemalloc/license.html BSD-derived license] | |||
* tcmalloc_bi - not available yet, based on [http://code.google.com/p/google-perftools/ TCMalloc], distributed under [http://www.opensource.org/licenses/bsd-license.php New BSD license] | |||
* nedmalloc_bi - not available yet, based on [http://www.nedprod.com/programs/portable/nedmalloc/ NedMalloc], distributed under [http://www.boost.org/users/license.html Boost Software License] | |||
* customMalloc_bi - not provided, feel free to plug-in your own | |||
You can also specify a particular allocator from a command line, like -malloc=tbb4malloc_bi, or -malloc=mybestmalloc_bi (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 extenstion) |
Revision as of 13:08, 27 October 2011
Since Arma 2 Operation Arrowhead build 85869 (1.60 beta) it is possible to provide custom memory allocators for the game.
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 };
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.
Specifying a custom allocator
The allocator is a dll placed in dll directory located next to the game executable. Allocator search order is:
- tbb3malloc_bi - based on Intel TBB 3, distributed under GPL v2 + RE
- tbb4malloc_bi - based on Intel TBB 4, distributed under GPL v2 + RE
- jemalloc_bi - not available yet, based on JEMalloc, distributed under BSD-derived license
- tcmalloc_bi - not available yet, based on TCMalloc, distributed under New BSD license
- nedmalloc_bi - not available yet, based on NedMalloc, distributed under Boost Software License
- customMalloc_bi - not provided, feel free to plug-in your own
You can also specify a particular allocator from a command line, like -malloc=tbb4malloc_bi, or -malloc=mybestmalloc_bi (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 extenstion)