A
A
Andrei Vukolov2018-02-28 19:10:33
Qt
Andrei Vukolov, 2018-02-28 19:10:33

How to quickly construct a large QByteArray from parts of other QByteArrays?

The following task arose: data arrives in the form of packets with headers wrapped in a QByteArray . It is required very quickly (3072 operations per second) to extract raw data from these packets, cleared of headers, and then throw them into one large QByteArray for further processing. The problem is overhead: the constant copying and reallocation of memory when calling append () eats up time, and data begins to be lost. At the same time, you cannot go beyond Qt due to the cross-platform requirement.
Can you suggest a way to overcome the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2018-02-28
@vt4a2h

I see several options:
1) Pre-allocate/reserve memory in the resulting container (resize()/reserve()). You can just allocate a lot of memory somewhere and use it as a buffer.
2) Use a different data structure for the result. But there must be a balance here, perhaps you will lose the advantage of the cash line, but perhaps this will not be critical.
3) You can simply store objects in some structure, and then collect them when enough accumulates.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question