Knowledge Base: Dealing with Allocator Mismatches with External Libraries

Dealing with Allocator Mismatches when using external Libraries
Unreal Engine uses its own allocators, a.k.a. new()/delete() implementation, such as mallocbinned2. Deleting memory that has been allocated outside of Unrea…

https://dev.epicgames.com/community/learning/knowledge-base/Eoyd/unreal-engine-dealing-with-allocator-mismatches-with-external-libraries

4 Likes

I could see tooling this. At least for Windows.
First of all for all your modules #undefine malloc, then #define malloc FMemory::Malloc(args) kind of thing. And at the top header redirect new and delete to the allocators you list.

Make it a practice to not use standard names, use the FMemory ones across the board.
Finally make a post build Python processing tool using LIEF or pefile module to parse the IAT of all built executable modules to capture any and all uses of CRT malloc, new, delete, etc.
Build failure is the use of any of these problem APIs.
Nip the problem in the bud before it manifests in crashes…

I am trying to build a library that can be used by unreal or other systems but I heavily rely on STL and build my components as a set of dlls for various reasons. How do I support allowing unreal developers to provide a custom allocator(Unreals allocator)?

Hey @UE_Seb.Tho,
does this also work for Android using .a files instead of .so?