Assuming we only instantiate less than 20 objects of class Blob and regarding efficiency (time execution) and memory management issues, is there a best option between:
-
Setting the random generator and the generated distributions as private class members such as:
class Blob { private: std::mt19937 engine; std::uniform_real_distribution<double> R_distribution; std::binomial_distribution<int> B_distribution; }
and using them directly in Blob methods. Thus when we call a distribution, we also alter the state of the engine that is a member.
-
Or setting the random generator as a private class members and passing the distributions by reference to the methods? For instance:
class Blob { private: std::mt19937 engine; //engine } void Blob::run() { int blabla = 10; std::uniform_real_distribution<double> R_distribution(0, 10); do_something(blabla, R_distribution); ... }
While passing by reference induce lower overhead in general, does it matter in that case in particular? How does the overall question scale when calling the distributions a huge number of times (10^9 or more)?
Aucun commentaire:
Enregistrer un commentaire