x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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:

  1. I am attempting to pass data between my code and certain key DLLs I am using - however, due the fact that UE4 uses an inherently different allocator than standard C++ (msvc), I am receiving heap corruption errors whenever something of mine is deallocated by the DLL, or I deallocate something provided by the DLL. Obviously, the second of those two is fairly avoidable, but I cannot prevent the DLLs from deallocating at some point - I do not have that much control over them.

  2. I have tested out a couple of things, mainly hunting down Unreal's "new" and "delete" operators to see what they do. Even after finding them, I can't really remove them, as attempting to comment them out simply results in the build failing at the UnrealHeaderTool.

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!

Product Version: UE Github Master branch
Tags:
more ▼

asked May 24 '18 at 02:56 PM in C++ Programming

avatar image

jeppreston
1 2 1

avatar image GBX_botman May 24 '18 at 04:21 PM

Have you thought about creating your own DLL to allocate/deallocate using the standard C++ library (and bypass using Unreal to allocate/deallocate)?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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):

http://api.unrealengine.com/INT/API/Runtime/Core/GenericPlatform/FGenericPlatformMemory/index.html

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

more ▼

answered May 25 '18 at 09:49 PM

avatar image

Shadowriver
36.6k 930 169 1111

avatar image jeppreston Jun 04 '18 at 07:11 PM

So, say that I have a UObject that I place into my world that handles all of the network communication with another program.

At some point, in order to send back some relevant data, I must throw together a data packet that contains some key information about a few of my entities.

I create an instance of the packet class, and after getting the necessary data, call a member of that instance. This member dips into the .DLL in which the class is defined, and everything starts to go bad from there.

As near as I can tell, the error stems from the fact that this member function creates an instance of yet another class, which is then, at the very end of the function, added to a std::vector<...> member within my packet instance. The error is produced by this .DLL-created class instance, which must have something intrinsically different about it, attempting to be .push_back(...)'d into my UE4-created class instance.

This sounds and seems like a difference into allocation between the two, but in the end I'm not 100% positive! Any tips?

Thanks for responding, by the way! I appreciate the help!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question