Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. What is optimal way to manipulate with large data QByteArray or char* dinamic array?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved C++ Gurus
10 Posts 3 Posters 5.4k Views
  • 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 Offline
    Q Offline
    qxoz
    wrote on last edited by
    #1

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

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

      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
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

        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
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          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
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            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
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              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
              0
              • Q Offline
                Q Offline
                qxoz
                wrote on last edited by
                #7

                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
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #8

                  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
                  0
                  • Q Offline
                    Q Offline
                    qxoz
                    wrote on last edited by
                    #9

                    [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
                    0
                    • Q Offline
                      Q Offline
                      qxoz
                      wrote on last edited by
                      #10

                      [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
                      0

                      • Login

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