egi-megi / porr-pso

2 stars 0 forks source link

Particles vector initialization in Swarm #8

Open mpiku opened 3 years ago

mpiku commented 3 years ago

Initialization of vector <Particle> swarm in the constructor initialization list might result in inefficient construction of Particle objects in the vector. I am not sure, but it results in reallocating vector memory later or constructing particle objects twice.

https://github.com/egi-megi/rojCzastek_Szczepanski_Jurkiewicz_Pikulinski/blob/3a730fc57c51f2a00332cec6067e04f5e872b4b5/src/Swarm.cpp#L18-L19

https://github.com/egi-megi/rojCzastek_Szczepanski_Jurkiewicz_Pikulinski/blob/3a730fc57c51f2a00332cec6067e04f5e872b4b5/src/Swarm.cpp#L26-L27

mpiku commented 3 years ago

I guess Particles will be copy-constructed in Swarm::makeSwarm. Since we have default constructor and the object is not heavy weight yet it shouldn't be a problem.

We might consider changing vector in Swarm to vector<Particle*> swarm in future.