0
votes

I'm writing an application in Qt that permits the video streaming from a byte array. As video output component I'm using QtAV (http://www.qtav.org/). In my case the input of this component is a QIODevice (QBuffer) where has a QByteArray with my data. I will put during the streaming the data inside the QByteArray, but I don't know how to delete the data that I have yet read. My problem is that after a little time, the dimension of QByteArray is very huge and I don't know how I can reduce the memory allocated.

Thank you

Angelo

1

1 Answers

0
votes

You can simply get a reference to a byte array object from your buffer using the method
QByteArray &QBuffer::buffer() and then erase it:

your_io_buffer.buffer().resize(0);

But please note that frequent removal and appending data to a dynamic array will cause memory reallocations, which is not so fast operation. Therefore I recommend to use the
void QByteArray::reserve(int size) method:

QByteArray buf;
buf.reserve(100000);
//...
your_io_buffer.setBuffer(&buf);
//...