What is optimal way to manipulate with large data QByteArray or char* dinamic array?
-
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.
-
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);
@ -
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.
-
[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.