0

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 Answers1

0

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);
//...
Vladimir Bershov
  • 2,701
  • 2
  • 21
  • 51
  • I created a new QIODevice that remove the bytes that the AvPlayer has read. The problem is that I can't remove all bytes because the AvPlayer reads 32k bytes per time. thank you very much for your answer. – Angelo Mantellini Dec 16 '16 at 13:55