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
Forum Updated to NodeBB v4.3 + New Features

Problem in Qvector initialization

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 1.5k 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 7 Jun 2017, 10:01 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);
    
    J K 2 Replies Last reply 7 Jun 2017, 10:16
    0
    • A Alexanov
      7 Jun 2017, 10:01

      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);
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 7 Jun 2017, 10:16 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 7 Jun 2017, 10:56
      2
      • A Alexanov
        7 Jun 2017, 10:01

        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 7 Jun 2017, 10:18 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
        • V Offline
          V Offline
          VRonin
          wrote on 7 Jun 2017, 10:32 last edited by VRonin 6 Jul 2017, 10:38
          #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
          • J jsulm
            7 Jun 2017, 10:16

            @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 7 Jun 2017, 10:56 last edited by Alexanov 6 Jul 2017, 11:06
            #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

            1/5

            7 Jun 2017, 10:01

            • Login

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