How do I change UE4's default allocator?
I have recently begun to have problems in relation to Unreal's overriding of the new and delete operators, particularly when passing between the DLLs I am attempting to use and my code. I am consistently getting heap corruptions due to the fact that Unreal seems to use a different allocator than the standard C++ allocator.
I have attempted a few things, mainly looking through the Engine's source code to find instances of the allocators being used, and to see the different allocators available. I have had a particular interest in GMalloc, and FMalloc as a whole, due to their use in the garbage collection that Unreal does. I have attempted to change GMalloc to use different FMallocs, particularly being interested in MallocAnsi, as I would presume that that falls most closely in line with the default C++ allocators.
Overall, I'm not really sure where to go from here. To reiterate:
I'm reaching a dead end here. If I can't successfully solve or circumvent this issue, I will be forced to stop using Unreal Engine for my product, and likely rebuild from the ground up the past few months of work in another engine. I do hope that this has a solution, and thanks in advance for the help!
asked May 24 '18 at 02:56 PM in C++ Programming
No body force you to use UE4 allocation, no body force you to use UObject and UPROPERTY() this is only thing memory managed by UE4, UE4 don't alter C++ in any way everything is 100% C++ valid, fact that it use extra tools to generate some code don't change that. So you are free to use standard C++ library, just keep in mind type used i there is not compatible with UE4 APIs and you need to convert them first to make it work with rest of UE4 code.
If your DLL is so sensitive on memory allocation build a wrapper in main class of your module (if you didn't notice UE4 is modular and by making C++ project you just making extra module to the engine code), by default there macro that generate module class for you, but you can replace it with your own start up sequence for your module and use it as access point for low level APIs. I recommend to check out ho HTTP module is build as example, there many modules that fucntion similar way with singetlon and Get() function you can use elsewhere:
https://api.unrealengine.com/INT/API/Runtime/HTTP/index.html https://github.com/EpicGames/UnrealEngine/tree/8e4560b8c22b309e73ff0ce90377742c3dfe13cc/Engine/Source/Runtime/Online/HTTP https://github.com/EpicGames/UnrealEngine/blob/8e4560b8c22b309e73ff0ce90377742c3dfe13cc/Engine/Source/Runtime/Online/HTTP/Private/HttpModule.cpp
As long as you not inside UObject class tree any memory allocation should be under your full control, when your module is unloaded you should cease connection from DLL and renew it on when you module is loaded again. UE4 provides wrapper code for platform memory allocation functions in here (just use FPlatfrom insted of FGenericPlatfrom):
But again you free to use standard C++ APIs if you want to just you may hit platform compatibility issues if you try to package to different platforms
Follow this question
Once you sign in you will be able to subscribe for any updates here