Important: Please read the Qt Code of Conduct -

Restricting QtConcurrent::blockingMap

  • We currently have the following call in our code:

    QtConcurrent::blockingMap(sequence, function);

    to call function once for eatch item in sequence. During some memory debugging, we noticed that this call is eating a lot of memory. We are willing to sacrifice some execution time to decrease the memory usage. We were wondering if one could somehow restrict the number of parallel executions of 'function' so that our memory consumption is not too high, but we could not find anything in the documentation at

    Is there a way to do this?

    Kind regards,

  • Qt Champions 2017

    Try setting a fewer threads in the global pool (by default QThread::idealThreadCount is used):

    int threads = QThread::idealThreadCount() / 2;
    QThreadPool::globalInstance()->setMaxThreadCount(threads == 0 ? 1 : threads);

    Kind regards.

  • Lifetime Qt Champion


    What are you using as a container ?

  • @SGaist said in Restricting QtConcurrent::blockingMap:

    What are you using as a container ?

    QVector, but I am wondering why you are asking this and why that is relevant? The high memory consumption is due to the fact that function does some OpenCV image processing on the stuff that is in sequence. Each call to function loads some images in memory and processes them. Doing that in parallel with QtConcurrent::blockingMap thus increases our memory usage dramatically, because we have lots of images loaded in memory. If we could limit the number of times function is run in parallel, we could somehow reduce the memory load (giving up some execution speed though, but we can probably live with that).

  • My question is no longer relevant. After some further investigation, it turned out that the high memory consumption was not in the call to QtConcurrent::blockingMap(sequence, function). The memory allocations are located after this call.

    Nevertheless thanks for the suggestions!

Log in to reply