Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem in Qvector initialization
Qt 6.11 is out! See what's new in the release blog

Problem in Qvector initialization

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alexanov
    wrote on last edited by
    #1

    Hi
    I face to amazing problem !!!
    can any body say me the reason of this reaction ?
    when I wrote first line code , and debug my code this line allocated 15GB RAM but when replace number of array with scientific symbol this problem solved and my app work regularly .

    //Qvector initialization 
    
    1- QVector <QByteArray> vector(200000000);
    
    // Replace number with scientific symbol
    2- QVector <QByteArray> vector(2e8);
    
    jsulmJ K 2 Replies Last reply
    0
    • A Alexanov

      Hi
      I face to amazing problem !!!
      can any body say me the reason of this reaction ?
      when I wrote first line code , and debug my code this line allocated 15GB RAM but when replace number of array with scientific symbol this problem solved and my app work regularly .

      //Qvector initialization 
      
      1- QVector <QByteArray> vector(200000000);
      
      // Replace number with scientific symbol
      2- QVector <QByteArray> vector(2e8);
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Alexanov Interesting. Just tested on Windows 7: works and consumes only 12MB RAM. Are you sure it is not something else in your app?
      What is your OS, compiler and Qt version?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      2
      • A Alexanov

        Hi
        I face to amazing problem !!!
        can any body say me the reason of this reaction ?
        when I wrote first line code , and debug my code this line allocated 15GB RAM but when replace number of array with scientific symbol this problem solved and my app work regularly .

        //Qvector initialization 
        
        1- QVector <QByteArray> vector(200000000);
        
        // Replace number with scientific symbol
        2- QVector <QByteArray> vector(2e8);
        
        K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        @Alexanov

        Check the size of the actual vector allocated in both cases.

        qDebug() << "vector size " << vector.size();
        

        The scientific representation is most likely not converted to the int number you are expecting.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        2
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          Tried with Qt 5.8 on Win7 and:

          MSVC 2013 x64
          Both versions allocate the correct amount of memory: (200000000 * sizeof(QByteArray)) + sizeof(QVector<QByteArray>) = (200000000*8)+8 = ~1.6GB

          MSVC 2013 x32
          Both versions allocate the correct amount of memory: (200000000 * sizeof(QByteArray)) + sizeof(QVector<QByteArray>)= (200000000*4)+4 = ~800MB

          @koahnig said in Problem in Qvector initialization:

          qDebug() << "vector size " << vector.size();

          use capacity() instead of size() in this case.

          What compiler/OS/architecture are you using?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          3
          • jsulmJ jsulm

            @Alexanov Interesting. Just tested on Windows 7: works and consumes only 12MB RAM. Are you sure it is not something else in your app?
            What is your OS, compiler and Qt version?

            A Offline
            A Offline
            Alexanov
            wrote on last edited by Alexanov
            #5

            @jsulm ,@koahnig ,@VRonin
            :)) Oh Sorry Thanks alot for your answers, I saw code again , my number had 9 zero in it not 8 zero.
            2000000000 (2e9) not 200000000 (2e8)!
            And RAM allocation for 2e9 is correct:
            (200000000*8)+8 = ~16GB

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved