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



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



  • 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.



  • 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.



  • 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?



  • 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);
    @



  • 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.



  • 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.



  • 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).



  • [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.



  • [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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.