std::map
provides an std::map::size
function which only returns the number of elements.
Assuming an std::map
of int
/std::string
pairs, one may get the actual allocated memory per pair using sizeof(int)
and str.capacity()
respectively and then sum them up per insert. This causes lots of overhead.
An alternative would be to take a random sample of pairs and num of elements to estimate the total capacity, optionally apply some theory of estimation (maximum likelihood, confidence interval).
I need some "capacity" function for the std::map
. Is there a better way then the two approaches mentioned above?
Aucun commentaire:
Enregistrer un commentaire