mercredi 20 mars 2019

What's the fastest way to reinitialize a vector?

What is the fastest way to reset all values for a large vector to its default values?

struct foo
{
  int id,
  float score
};

std::vector<foo> large_vector(10000000);

The simplest way would be to create a new vector, but I guess it takes more time to reallocate memory than to reinitialize an existing one?

I have to iterate over the vector to collect non-zero scores (could be thousands or millions) before resetting it. Should I reset the structs one by one in this loop?

Aucun commentaire:

Enregistrer un commentaire