I think u should take the line: tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
out of the while loop. Since it performs allocation for the socket. doing this inside the loop allocates many socket. It's better to allocate single socket, and connect to the server using the allocated socket. Regards,... TheOldWiseKing ----- Original Message ----- From: Andreanes Yosef Vanderlee To: [email protected] Sent: Thursday, September 06, 2007 9:43 AM Subject: [c-prog] optimizing this part of code Hi... I have a problem with this code: ---------------------------------------------------------- do{ delay(1500); /* if I remove this, memory usage will grown so fast */ close(tcp_socket); tcp_socket = socket(AF_INET, SOCK_STREAM, 0); ret2 = connect(tcp_socket, (struct sockaddr*)&peer, sizeof(peer)); }while(ret2 != 0); ---------------------------------------------------------- that part of code will try to connect to server as long as the server is still down. My problem is, if I remove delay there, memory usage will grown very fast, so does the CPU usage (in 1 tested pc, it hang). But if I put that delay, the CPU usage is not high, but the memory usage is still going bigger n bigger as long as the server is down. I try to put that delay, and cut the connection to the server (so that it'll always run that part of my code) for about 1 hour, and the memory usage is growing from 1.8MB to 6.8MB. Should I put something on my code to refresh the memory? Thanks in advance -- Andreanes Yosef Vanderlee Phone: +62817 139 308, +62815 915 2766 homepage: http://vanderlee.web.id YM!: andre_flea gtalk: [EMAIL PROTECTED] msn: [EMAIL PROTECTED] skype: andre_flea friendster: http://friendster.com/vanderlee [Non-text portions of this message have been removed]
