Constructing a lot of small objects - performance, memory fragmentation

And I mean A LOT. Like 100k each second.

Few questions:

  1. How efficient it is using ConstructObject.
  2. What about memory fragmentation. Do I have to really worry about fragmented memory from allocating and destroying lots of small objects, or it is generally non-issue ?
  3. Should I rather try to create objects in advance and use already created objects, instead of constructing new one each time ?

For what do you need that much objects? You should rethink your design.

  1. Do you also destroy objects as fast as you create them?

Well this was extreme use case I doubt it will ever get higher than several thousand.

I need these objects to handle damage dealing.

  1. Some objects just apply attribute change on final target.
  2. Other object modify above. So you can have handful of blueprints with specific formulas/events for handling specific type of damage. For example, Fire, Spell, Physical, can be combined in any possible way, by just chaining modifier effects.
  3. And finally there are effects that apply other effects. For example over time or in area.

I decided to do it this way, because it fairly easy to use in blueprint and flexible enough, to do not need to rely on constantly adding new functionality in C++.

Try to create a pool of thos objects, existing somewhere in the world, and whe nyou use them, instead of creating, just set their location, and initialize them, then when they should get destroyed, set the location back to somewhere far away and deinitialize them.

1 Like

Thanks. Well It might have worked if not for the fact that these objects were realying on actor attributes, to set values in their own in real time. And once they are created, the values are set.
I know I can find object modify it, and after that just apply it to other actor. I had similiar solution worked out before, but it was really awkward to use.

In any case I solved my problem in whole different way. Instead of trying to figure out some odd generic solution, I just written the most heavy functionality to be game specific, and now it is just handful of static functions.

Hi I’m curious that if this kind of action causes memory fragmentation too.
Does anyone knows how Unreal handle memory allocation?
I haven’t study the source code but I guess UE is using some kind of pre-allocated memory pool, so there should not be any fragmentation issue, is it?

static functions are … you know … static … and dangerous. I’m curious why won’t pooling work? If you need the actor, keep a reference to them?

Unfortunatly, a pre-allocated memory pool doesn’t prevent memory fragmentation. It can help lower it, but it’s not a cure.