Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    What is optimal way to manipulate with large data QByteArray or char* dinamic array?

    C++ Gurus
    3
    10
    4837
    Loading More Posts
    • 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.
    • Q
      qxoz last edited by

      Can QByteArray store and manipulate with data over 10 000 bytes,
      Or better use another data types such as char* ?

      1 Reply Last reply Reply Quote 0
      • A
        andre last edited by

        The best datastructure to use depends for a very large part on what you want to use the data for. That is: how do you plan to access the data? Do you plan to manipulate the data? Do insertions? Appends? In-place modifications? Do you need indexes? Searches? Etc. Etc. Just by giving a size, there is no way to advice you a datastructure to use. Of course QByteArray can handle more than 10kb.

        1 Reply Last reply Reply Quote 0
        • Q
          qxoz last edited by

          Well?, i use byte array as copy of device memory. After getting variables i need and make changes which i need upload the data back into device.

          1 Reply Last reply Reply Quote 0
          • Q
            qxoz last edited by

            And about QByteArray:
            Its very good solution for me, but it's impossible modify bytes, and i remove byte and insert new byte in removed place.
            Is realy impossible edit bytes stored in byte array?

            1 Reply Last reply Reply Quote 0
            • L
              lgeyer last edited by

              I would go for another solution then. Create a struct which maps the layout of you device data and then copy the data into it. This keeps your code much more readable then fiddling with char* or QByteArray.

              @
              typedef struct
              {
              uint8 flagA;
              uint32 variableA;
              uint32 variableB;
              uint8 fieldA[1024];
              uint8 fieldB[1024];
              ...
              } DeviceData;

              DeviceData deviceData;

              getDeviceData(&deviceData);

              deviceData.flagA = 1;
              deviceData.variableA = 1024;
              memcpy(deviceData.fieldA, someData, 1024);
              ...

              setDeviceData(&deviceData);
              @

              1 Reply Last reply Reply Quote 0
              • A
                andre last edited by

                Lukas is right. However, you can modify the contents of QByteArray in-place, if you want to. The [] operator is one way to do it.

                1 Reply Last reply Reply Quote 0
                • Q
                  qxoz last edited by

                  Well i have whole class which get data by name of variables, but types of devices are about 20 kinds. And 40%-70% of variables are similar, this reason to not create new class type for every device. I use different methods for different devices, which are has access to data stored in bytearray.

                  1 Reply Last reply Reply Quote 0
                  • L
                    lgeyer last edited by

                    I'm not quite sure if I understand your last post correctly, but if it is about just storing a bunch of data with random access then I see no sense in using anything other than char* (or whatever alignment you prefer).

                    1 Reply Last reply Reply Quote 0
                    • Q
                      qxoz last edited by

                      [quote author="Andre" date="1322065867"]Lukas is right. However, you can modify the contents of QByteArray in-place, if you want to. The [] operator is one way to do it.[/quote]

                      [] operator is exactly what i need and it works.

                      1 Reply Last reply Reply Quote 0
                      • Q
                        qxoz last edited by

                        [quote author="Lukas Geyer" date="1322068030"]I'm not quite sure if I understand your last post correctly, but if it is about just storing a bunch of data then I see no sense in using anything other than char* (or whatever alignment you prefer).[/quote]

                        And again sorry for my English :).
                        QByteArray has a couple of useful features, and also has the ability to access data through operator []. As Andre said, 10k is easy for QByteArray.
                        For my case it's enough.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post