What is the best way to create a circular buffer in Qt? I would just do something like this:
vidoudpsocket.h
typedef struct
{
CircularBuffer *before
quint16 *data;
CircularBuffer *next;
} CircularBuffer;
videoudpsocket.cpp
VideoUDPSocket::VideoUDPSocket(QObject *parent)
: QObject(parent)
{
CircularBuffer buffer0, buffer1, buffer2, buffer3, buffer4, buffer5, buffer6, buffer7;
buffer0.before = buffer7;
buffer0.data = (quint16 *) malloc(16384*16384);
buffer0.next = buffer1;
//...
}
Is this a good way to implement it in Qt or is there a better?
Thank you!
Edit:
My first try do not even seems to work, the compiler does not know what to do with CircularBuffer
inside the structure.
I now try to use QVector but i alwas get the Error allocating memory for data[i]
-Debug-Message (at i > 7809).
#define MAXNUMBERRANGEBINS 8192
QVector<quint8**> ringBuffer;
ringBuffer.resize(8);
foreach(quint8** data, ringBuffer)
{
data = (quint8**) malloc(MAXNUMBERRANGEBINS*2*sizeof( quint8* ));
if(data == NULL)
qDebug() << "Error allocating memory for data";
for(int i = 0; i < MAXNUMBERRANGEBINS*2; i++)
{
data[i] = (quint8*) malloc(MAXNUMBERRANGEBINS*2);
if(data[i] == NULL)
qDebug() << "Error allocating memory for data[" << i << "]";
}
}
Edit2 If I calculated right, my array is about 270MB big per buffer, that should explain the memory allocation error, am I right?