[英]QtAV and cleaning of the buffer
I'm writing an application in Qt that permits the video streaming from a byte array. 我正在Qt中编写一个应用程序,该应用程序允许从字节数组流式传输视频。 As video output component I'm using QtAV ( http://www.qtav.org/ ).
作为视频输出组件,我正在使用QtAV( http://www.qtav.org/ )。 In my case the input of this component is a QIODevice (QBuffer) where has a QByteArray with my data.
在我的情况下,此组件的输入是QIODevice(QBuffer),其中包含一个包含我的数据的QByteArray。 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.
我将在流式传输过程中将数据放入QByteArray内,但我不知道如何删除尚未读取的数据。 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.
我的问题是,过了一会儿,QByteArray的尺寸非常大,我不知道如何减少分配的内存。
Thank you 谢谢
Angelo 安杰洛
You can simply get a reference to a byte array object from your buffer using the method 您可以使用方法简单地从缓冲区中获取对字节数组对象的引用
QByteArray &QBuffer::buffer()
and then erase it: QByteArray &QBuffer::buffer()
,然后将其擦除:
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: void QByteArray::reserve(int size)
方法:
QByteArray buf;
buf.reserve(100000);
//...
your_io_buffer.setBuffer(&buf);
//...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.