This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C++ vector without dynamic reallocation?

Hi

We want to use a C++ vector in our application, but the Dinkumware vector class provided by CGT 6.1.10 is too slow for us (a push_back() call takes ~50ns on a 6488 clocked at 1GHz).

The issue is that the vector class supports dynamic reallocation such that the vector may grow beyond its present capacity if necessary. So push_back() must always check that there is sufficient storage for the new element, and allocate more memory if necessary.

In our app, our vector will never grow beyond its initial capacity. Therefore, the complexity (and resulting speed penalty) of the Dinkumware class is not required.

Does anyone know of a C++ vector class that provides an unchecked push_back() method, or that does not support dynamic reallocation please?

Best regards

David

 

  • May be old-time С arrays is what you need for fixing size.

  • A few points to consider ...

    Good performance on STL code requires the compiler perform function inlining.  To get inlining you must use the build flags -o2 or -o3, preferably -o3.

    The usual way to avoid vector reallocation is to to use the reserve() function to reserve, up front, enough memory for a given number of elements.  This technique is documented in section 6.2.1 of the book The Standard C++ Library by Josuttis.  Or perform an internet search on "stl reserve vector".

    While I'm sure these techniques will improve performance, I don't know if it will be enough to meet your goals.

    Thanks and regards,

    -George

     

  • Please avoid using 6.1.10 release. It is a release with a known serious performance drop bug. On our external download site, 6.1.10 is alreay removed.

    Please try to use the most recent release 6.1.13.