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

QByteArray maximum size

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 15.0k 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.
  • G Offline
    G Offline
    goocreations
    wrote on last edited by
    #1

    The size() function of QByteArray returns an int. The maximum value of an int is 2147483647 (which is 2GB) or unsigned 4294967295 (4GB). What happens if the size of the array is larger than that size, shouldn't it return a qint64? Or is it even possible to create QByteArrays larger than 2GB?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      QByteArray supports up to 2GB of memory usage. Bigger blocks are not supported.

      Note that it will be hard to even acquire such a huge continious memory block in one go on most systems today. If you need bigger structures, you probably will be better off using your own custom memory structure.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        broadpeak
        wrote on last edited by
        #3

        Hm, interesting:

        @
        QByteArray* ba = new QByteArray ( 3000000000, 'a' );

        if (ba)
            cout << "OK" ;
        else
            cout << "NOT OK";
        
        cout << "\nsize of ba: " << ba->size();
        

        @

        output:
        OK (pointer is created...)
        size of ba: 0 (???)

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          You are simply hit by a signed integer overflow and your number wraps around, actually passing <code>-1294967296</code> to the QByteArray constructor (the two's complement of <code>3000000000</code>), which leads to a zero-sized byte array (as a negative size is passed).

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goocreations
            wrote on last edited by
            #5

            QBuffer works with qint64, and you can setBuffer(QByteArray). Does anyone know the behaviour if you now try to add more than 2GB to the QBuffer? Will it create a second QByteArray, or will it bomb out?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Why don't you just try and see? I mean: it should be easy enough to test this I think.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goocreations
                wrote on last edited by
                #7

                I currently only have 3GB memory on my workstation so I can't really test it. But thanks anyway, I don't think my program users will ever use more than 1GB or so.

                1 Reply Last reply
                0

                • Login

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