Tuesday, April 9, 2019

architecture - Which of these two particle generator lifetime management techniques is better?


What would be better:




  1. An explosion class which gets created when needed, does it's stuff, then is deleted. (one instance per explosion)

  2. An explosion class which persists through the whole game, and creates a new explosion in the appropriate place when needed. (one instance per game)



Answer



Probably the first option, as the second option implies you can only have a single explosion in any given frame. Unless you're talking about having a factory produce the explosion objects in the second option, in which case the two options are not mutually exclusive and you probably should, in fact, do both.


Regardless, the only downside to the first option (at this rough level of abstraction) is the cost of allocation churn. This can be alleviated using an allocation pool for your explosion object instances (for example, in the factory that produces explosions), which will will allow you to have the logically correct model of explosions (that is, there can be multiple explosions and each explosion has an associated object instance) without incurring the overhead of frequent allocations during runtime.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...