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. (ALL Containers Use INT.) What can save live data in memory if the data length is 'qint64' ?
Forum Updated to NodeBB v4.3 + New Features

(ALL Containers Use INT.) What can save live data in memory if the data length is 'qint64' ?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 4.1k 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.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #1

    OLD TITLE: How can QIODevice read 'qint64 maxSize' and return a QByteArray when the interface of QByteArray is 'int' based NOT 'qint64' based?

    I am very confused. If I pass a 'qint64' to a function that takes an 'int', then doesn't the qint64 become an int???

    The entire interface to QByteArray has all 'int's as parameters/return values like int size(), resize(int), etc.. So therefore how can a QByteArray be longer than the maximum length of an int?

    Furthermore, the interface to QBuffer (in addition to QIODevice) is all 'qint64' based yet QBuffer is built on an internal QByteArray.

    So Is it possible to set the size of QByteArray to be larger than an int when the API is built on ints?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      roopeshchander
      wrote on last edited by
      #2
      • Yes, a QByteArray can't hold data bigger than MAX_INT bytes
      • QBuffer uses qint64 because it derives from QIODevice and has to provide the same interface as a QIODevice. Despite using qint64 in the interface, a QBuffer too can't hold data bigger than MAX_INT bytes.

      As to why QIODevice uses qint64, but QByteArray uses int, I'm afraid I have to guess: QByteArray is only something like a better alternative for the simple char * - so it's interface is in terms of the more straightforward int, the type you would normally use to index char *s. QIODevice is a generic read-write interface that's used as a base for file and network access, so it's probably designed to be able to handle potentially huge chunks of data.

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        roopeshchand.. Ok, if like I think - a QByteArray can't hold data bigger than MAX_INT (maximum size of a regular 'int' integer), then what is the meaning of this interface in QIODevice:

        @
        QByteArray QIODevice::read ( qint64 maxSize )

        Reads at most maxSize bytes from the device, and returns the data read as a QByteArray.
        @

        If it reads a maxSize amount of data of qint64 then how will that fit inside a QByteArray?

        If the other classes are using the QByteArray that has an 'int' interface, then why do the other classes have 'qint64' interfaces? Anyway, what is one to use to store something in memory that contains data of length longer than int?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dangelog
          wrote on last edited by
          #4

          Consistency with the other read() overloads?

          Software Engineer
          KDAB (UK) Ltd., a KDAB Group company

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #5

            peppe: I changed the title of the post. I am under the impression that QByteArray cannot save all data if the data size is larger than the maximum size of an integer. All of the containers seem to return sizes or lengths of 'int'.

            OLD TITLE: How can QIODevice read ‘qint64 maxSize’ and return a QByteArray when the interface of QByteArray is ‘int’ based NOT ‘qint64’ based?

            NEW TITLE: (ALL Containers Use INT.) What can save live data in memory if the data length is ‘qint64’ ?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Scylla
              wrote on last edited by
              #6

              You can use a list of QByteArrays. So you have enough space, isn't it?

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dangelog
                wrote on last edited by
                #7

                Don't use that read(qint64) overload, but create a suitable buffer and use the read(char*, qint64) one. The limitation of QByteArray is not a problem, since noone pretends to use it to manage a contiuous memory chunk longer than 2GB.

                In other news, what's the use case of reading more than 2^31-1 bytes at once from a device?

                Software Engineer
                KDAB (UK) Ltd., a KDAB Group company

                1 Reply Last reply
                0
                • ? This user is from outside of this forum
                  ? This user is from outside of this forum
                  Guest
                  wrote on last edited by
                  #8

                  OK pepe. But does your comment mean that a QByteArray can hold data up to 2GB? I thought QByteArray can only hold up to 32K bytes since the size is based on integer.

                  Some of the standard examples are having webpages 'readAll()' into a QByteArray through QNetworkReply. But many web pages have more data than 32K or more characters than 32K so if put into a QString, the webpage would be amputated.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    dangelog
                    wrote on last edited by
                    #9

                    [quote author="Iama Hummingbird" date="1315081309"]OK pepe. But does your comment mean that a QByteArray can hold data up to 2GB? I thought QByteArray can only hold up to 32K bytes since the size is based on integer.[/quote]

                    "int" is a 32 bit signed integer on all platforms supported by Qt. Therefore, you can index (and store) up to 2^32-1 bytes inside a QByteArray. Which means up to 2GB - 1B. That's why I was asking for an use case -- allocating a single, huge chunk of 2GB is not that common.

                    [quote]
                    Some of the standard examples are having webpages 'readAll()' into a QByteArray through QNetworkReply. But many web pages have more data than 32K or more characters than 32K so if put into a QString, the webpage would be amputated.
                    [/quote]

                    See above for the 32K part. But I think that this is quite a corner case, and you won't wait to buffer 2GB in memory before attempting to read it all at once -- you will read it as soon as possible (i.e. just after readyRead is emitted). This way you can safely download files even bigger than 2GB.

                    Software Engineer
                    KDAB (UK) Ltd., a KDAB Group company

                    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