Click here to Skip to main content
15,914,163 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: but... Pin
Hans Ruck21-Feb-03 3:16
Hans Ruck21-Feb-03 3:16 
GeneralRe: but... Pin
ns21-Feb-03 3:23
ns21-Feb-03 3:23 
GeneralRe: passing in an STL set pointer in SEndMessage Pin
AlexO21-Feb-03 2:35
AlexO21-Feb-03 2:35 
GeneralRe: passing in an STL set pointer in SEndMessage Pin
ns21-Feb-03 2:39
ns21-Feb-03 2:39 
GeneralRe: passing in an STL set pointer in SEndMessage Pin
ns21-Feb-03 2:41
ns21-Feb-03 2:41 
GeneralRe: passing in an STL set pointer in SEndMessage Pin
AlexO21-Feb-03 2:55
AlexO21-Feb-03 2:55 
GeneralRe: passing in an STL set pointer in SEndMessage Pin
ns21-Feb-03 3:04
ns21-Feb-03 3:04 
GeneralMemory leak Pin
Willem B21-Feb-03 1:58
Willem B21-Feb-03 1:58 
hi,

i've designed a program that runs as an server. If a connections request comes the program opens a thread that handles the commands for this connection.

This new thread construct a class that has all the thinking capabillaties for the thread, it also constructs a Class that handles the connection events(sending information/encrypting it and so on). The thread also receives the pointer to a "database server"(a class that handles all commands for the database) and sends it to the constructed class. Wenn a connection is made there will also be a Session-struct constructed(this hold all info about the connection, login-name/login-pass and so on).

The session is constructed as a "new" struct, wenn the thread ends the session is "deleted" so is doesn't remain in the memory.

if i run this program, and login and out a few hundred times the memory that is taken by the server seems to be growing... what can i doe to prevent this?

wenn the thread ends is the constructed class fully removed out of the memory? or do i have to do it myself?

thread code:

<small><br />
<br />
UINT ClientThreadRecv(LPVOID Client)<br />
{<br />
CCrypt Crypt; // class for decrypting info<br />
char Block[BlockSize]; // memory Block for receiving dataCString	Data, TData; // the final variable for storing the received data<br />
int loc;<br />
int namelen = sizeof(sockaddr_in);<br />
sockaddr_in name;<br />
char *ip;<br />
<br />
SOCKET client = (SOCKET)Client; // socket that the thread handles<br />
getpeername(client, (sockaddr *)&name, &namelen);<br />
ip = inet_ntoa(name.sin_addr); // client ip<br />
CGebruikersStruct *Session = new CGebruikersStruct; // the session, later on stored in a linked list, thats why the new.<br />
Session->client = client;<br />
Session->LoginNaam = "";<br />
Session->LoginPass = "";<br />
Session->LoggedIn = FALSE;<br />
Session->Rechten = 0;<br />
Session->IPadres = ip;<br />
<br />
CClientSocket ClientSocket; // global point for socket info/sending data<br />
ClientSocket.Session = Session;<br />
ClientSocket.DatabaseServer = DatabaseServer; // the pointer for the database<br />
CClientClass ClientClass; <br />
ClientClass.ClientSocket = &ClientSocket;<br />
<br />
ClientSocket.ConnectionBegin(); // a function that sends the client that the server is readywhile(true)<br />
{<br />
<br />
loc = recv(client, Block, BlockSize, 0); // receiving the data<br />
if ((loc == -1) || (loc == 0)) // end thread if socket is disconnected<br />
{ break; }<br />
Block[loc] = 0;<br />
<br />
Crypt.DeCrypt(Block, Block); // decrypting the received dataTData += Block; // add all data into 1 big variable<br />
if (TData.Mid(TData.GetLength() - EndKey.GetLength(), EndKey.GetLength()) == EndKey) // searches for the end key in the big variable, if found sends in to the class{<br />
if (ClientClass.ExcuteCmd(TData) == FALSE)<br />
{ break; } // if the class returns a quit(false) quit the thread<br />
TData = "";<br />
}<br />
<br />
}<br />
ClientSocket.ConnectionEnd(); // ends all open things, like memory blocks in the database server and that stuff<br />
delete Session; // speaks for itself<br />
<br />
closesocket(client); // closes the socketreturn 0; // ends the thread<br />
}<br />
<br />
</small>


[]D [] []D []
GeneralRe: Memory leak Pin
Willem B21-Feb-03 2:25
Willem B21-Feb-03 2:25 
GeneralBeginning Socket Programming Pin
lumpyandsuspicious21-Feb-03 1:25
lumpyandsuspicious21-Feb-03 1:25 
GeneralRe: Beginning Socket Programming Pin
valikac21-Feb-03 6:43
valikac21-Feb-03 6:43 
GeneralTool Tip in CFormView Pin
sikrip21-Feb-03 1:23
sikrip21-Feb-03 1:23 
GeneralRe: Tool Tip in CFormView Pin
Roger Allen21-Feb-03 1:43
Roger Allen21-Feb-03 1:43 
GeneralRe: Tool Tip in CFormView Pin
Aaron Schaefer21-Feb-03 6:18
Aaron Schaefer21-Feb-03 6:18 
Questiontab like control? Pin
Jon Hulatt21-Feb-03 1:22
Jon Hulatt21-Feb-03 1:22 
AnswerRe: tab like control? Pin
AlexO21-Feb-03 2:58
AlexO21-Feb-03 2:58 
GeneralMDI Menu Pin
albuemil21-Feb-03 0:43
albuemil21-Feb-03 0:43 
GeneralRe: MDI Menu Pin
Roger Allen21-Feb-03 1:47
Roger Allen21-Feb-03 1:47 
GeneralRe: MDI Menu Pin
albuemil21-Feb-03 2:30
albuemil21-Feb-03 2:30 
GeneralMoveWindow() Pin
ROK_RShadow20-Feb-03 23:53
ROK_RShadow20-Feb-03 23:53 
GeneralRe: MoveWindow() Pin
Chintan21-Feb-03 0:28
Chintan21-Feb-03 0:28 
GeneralRe: MoveWindow() Pin
ROK_RShadow21-Feb-03 0:35
ROK_RShadow21-Feb-03 0:35 
GeneralRe: MoveWindow() Pin
vikramlinux21-Feb-03 0:29
vikramlinux21-Feb-03 0:29 
GeneralRe: MoveWindow() Pin
ROK_RShadow21-Feb-03 0:33
ROK_RShadow21-Feb-03 0:33 
GeneralRe: MoveWindow() Pin
vikramlinux21-Feb-03 0:35
vikramlinux21-Feb-03 0:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.