PDA

View Full Version : Craching in QQueue



kiran p
4th August 2011, 15:45
Hi all,
I am working with a real time application where in i need to handle the data coming from socket at a speed of 2MBps.
i am using QQueue<QByteArray> where in i am reading 22 Bytes and storing it as QByteArray in QQueue after storing this data i will process it by taking 22Bytes at a time and updating it to a Qtreeview using QStandardItemModel.
my problem is i am not able to update the model at the rate at which the data is coming from socket resulting the QQueue is overloaded with huge data at after some time it is getting crashed.

Requesting help for the same.

Thanks in Advance.

yeye_olive
4th August 2011, 16:03
You do not provide enough information, and no code, so there is not much we can do to help you.

What does your program do exactly? I will take a few shots in the dark here. You seem to have a producer that reads data in blocks of 22 bytes from a socket and enqueues them as QByteArrays in the QQueue, and a consumer that dequeues and processes them. The producer and consumer run in parallel (in distinct threads?) and the consumer is not as fast as the producer, causing the queue to grow until the process goes out of memory.

Is that correct? Until you provide details and code I am afraid all you can get are generic (a.k.a. useless) answers.

kiran p
5th August 2011, 07:25
Thanks for your response.
Your assumption is right only thing differs is the producer and consumer runs in the same thread in my application.

Kindly revert for further clarification.

yeye_olive
5th August 2011, 09:57
Then if the producer and consumer run in the same thread how do you schedule them? I suppose that you enqueue a QByteArray as soon as you receive 22 bytes in reaction to the socket's readyRead() signal. But how do you decide that it is time to dequeue a QByteArray to process it?

You need a smart strategy for deciding when to process a bunch of QByteArrays, because the application will not be reading from the socket in that time frame. Or maybe a simpler design works, in which you just process every QByteArray as soon as you receive it, not bothering to go through a queue.

In any case, you can only hope to meet the real time requirements of your application if, on average, processing a QByteArray is faster than receiving it.