I am developing a program, where performance is critical. There I use a QMultiMap
, which is a class provided by the Qt framework, similar to std::map
.
QMultiMap<int, SomeClass> heavilyUsedMap;
void prepareMap()
{
...
heavilyUsedMap.reserve(nEntries); // There is no reserve.
// fill heavilyUsedMap with a known number of entries.
}
void useMap()
{
// computations
heavilyUsedMap.clear();
}
I use prepareMap()
a lot. When I want to optimize, it would make sense to allocate the memory for heavilyUsedMap
.
Indeed the containers: QVector<T>
, QHash<Key, T>
, QSet<T>
, QString
, and QByteArray
all provide this possibility, but QMap<Key, T>
and QMultiMap<Key, T>
don't.
Why is this so and how can I preallocate memory for the QMap<Key, T>
and QMultiMap<Key, T>
?