3

I have a file transfer application and I'm using a QDataStream to write data read from a QTCPSocket to a file. I thought when I wrote this that the QDataStream would remain at a fixed size but it seems that as I read from my socket and stream data out to my file, the memory of my application steadily rises, I was hoping to stream to the end of the file with each chunk and so not have to hold everything in ram.

//code a little something like this
QTCPSocket socket; //connected elsewhere
QFile f(fileName);
QDataStream ds(&f);
while(reading)
{
    socket.readRawData(data);
    ds.writeRawData(data);
}

Does anyone know how I can write to the file so that my memory doesn't steadily increase?

  • I cannot reproduce the problem. When I receive a large amount of data over a TCP socket and write it to a file with a `QDataStream` / `QFile` as in your example, I cannot observe the memory steadily increasing. Instead I see a constant amount of memory that is much smaller than the whole amount of data written to the file. It is possible that your code has a memory leak somewhere, but it is impossible to tell without seeing more of your code. – f9c69e9781fa194211448473495534 Oct 24 '20 at 11:11

0 Answers0