Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8482679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:52:53+00:00 2026-06-10T19:52:53+00:00

I am developing a program, where performance is critical. There I use a QMultiMap

  • 0

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>?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:52:54+00:00Added an answer on June 10, 2026 at 7:52 pm

    It’s most likely backed by a binary search tree, so preallocation isn’t common as it is usually a linked structure with each node dynamically allocated as required.

    If order is not important consider using a hash map instead, you can preallocate and it is also more performant generally. So QHashMap<int, SomeClass>.

    I also see your key type is int, if the domain is sufficiently small you can use a perfect hash which is essentially an array. So QVector<SomeClass>, which will be even more performant than a hash map.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I m developing a program that makes use of UIImagePicker custom class made by
We are developing a highly performance critical software in C++. There we need a
I am developing a program which needs to use os.system because of the old
I'm new in Java. I'm developing program for Android similar to app for iOS.
I'm developing a program which allows users to input some information which then gets
I'm developing a program that makes some floating points calculations. Is there any way
I am developing some program in C# which will send the mail using outlook
I am developing program which need to interact with COM ports. By learning from
i am developing a program which uses the android camera to take pictures. but
I am developing a program in Java that I will use for registering data.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.