Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TClientSocket eats ALL my memory??

Status
Not open for further replies.

MoonchildHK

Programmer
Jun 5, 2001
22
HK
Hi All,

I am having serious problems with the ftp part of a program I am writing. I have a several TClientSocket, the first of which connects to the control port (21) of the ftp server. The other one is used to actually x-fer the data (on a port assigned using PASV).

My problem is that when I am transfering big files (say 100Mb) then ALL my memory disapears and windows crashes!

Here is the code that is run from the OnRead handler for the TClientSocket. I open a file when the socket connects, and then save the data to the file on each read, then close the file on dis-connect. I have the following code in a TThread so that the program does not freeze with large files.

Code:
void __fastcall receiveFile::Execute()
{
 // Read data from the server
 int length;
 char *buffer;

 length = DataSocket->Socket->ReceiveLength();
 buffer = new char[10240];
 DataSocket->Socket->ReceiveBuf(buffer, length);

 fwrite(buffer, length, 1, fhCurrentFile);
 delete[] buffer;
}

The files turn up fine on the disk (they are video files.. and I can view them OK) but if I am x-fering a large file.. the memory just goes very fast! I am de-alocating the small amount of memory I am using for each read. I have also tried re-using the same memory, which I allocated at the start of the program and got the same results.. more and more meory being used until none left!

Could it be the ClientSocket is using memory to store the data before I read it, and then not freeing it again? How would I solve this?

If anyone has ANY ideas I would be most gratefull. I have been trying to solve this for days now with no sucess :-(

Thanks,

Steph
 
that may not be the problem, look for infinate loops, and look for anything that may institute your function to loop an infinate or excessive amount of times to where it makes too many of the same file. Cyprus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top