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

C / C++ / MFC

 
AnswerRe: Fetching records in Bulk Pin
Bravoone_200613-Sep-06 21:03
Bravoone_200613-Sep-06 21:03 
GeneralRe: Fetching records in Bulk Pin
Akt_4_U13-Sep-06 21:35
Akt_4_U13-Sep-06 21:35 
GeneralRe: Fetching records in Bulk Pin
Bravoone_200613-Sep-06 21:47
Bravoone_200613-Sep-06 21:47 
AnswerRe: Fetching records in Bulk Pin
David Crow14-Sep-06 3:18
David Crow14-Sep-06 3:18 
Questionhow to resolve Pin
Parshant Verma13-Sep-06 20:36
Parshant Verma13-Sep-06 20:36 
Questionhow to resolve linking error Pin
Parshant Verma13-Sep-06 20:35
Parshant Verma13-Sep-06 20:35 
AnswerRe: how to resolve linking error Pin
Hamid_RT13-Sep-06 21:21
Hamid_RT13-Sep-06 21:21 
QuestionMultithreaded server application - increase in application memory usage Pin
FFKONG13-Sep-06 20:07
FFKONG13-Sep-06 20:07 
I have created a multithreaded server application in Windows service. In the ServiceMain() function, a listening socket is created to listen for incoming client request. Upon acceptiong a new client request, a new thread will be created to handle that request. The client request is handled by the CMyThread class (parent class is CWinThread), but for debugging purpose, there is no specific implementation in the class yet. I observed that, the service application memory usage keeps on increasing against time. Each new client request will result in about 4K increase in application memory usage after the CMyThread servicing thread terminates. I am not quite sure how the AfxBeginThread() allocates memory in heap and how the CWinThread releases all used resources back to heap. During source debugging, I observed that the CMyThread object was deleted after the ExitInstance() was called.

The service application works well when no thread is created upon receiving new client request. Appreciate if someone can give me a hand on this. Thanks.

Below are snippets of the codes:

// service main function
void CMyService::ServiceMain(DWORD /*dwArgc*/, LPTSTR* /*lpszArgv*/)
{
:
:

CAsyncSocket socListen;
if (!socListen.Create(8080))
{
QuitService(strMsg);
return;
}
if (!socListen.Listen(200))
{
QuitService(strMsg);
return;
}

:
:

CSocket soc;
CMyThread* pThread;
while(!m_bStop)
{
if (socListen.Accept(soc))
{
pThread = (CMyThread*)AfxBeginThread(RUNTIME_CLASS(CMyThread), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);

if (!pThread)
{
soc.Close();
strMsg.Format(_T("Failed to create serving thread. Error: %s."), GetLastErrorText(GetLastError()));
AfxGetService()->m_EventLogSource.Report(EVENTLOG_ERROR_TYPE, CS_MSG_SERVICE_ERROR, strMsg);
return;
}

// Pass the socket to the thread by passing the socket handle.
pThread->m_hSocket = soc.Detach();

// start the thread.
pThread->ResumeThread();

}
Sleep(1000);
}

:
:
}





// CMyThread class: MyThread.h
class CMyThread : public CWinThread
{
DECLARE_DYNCREATE(CMyThread)

protected:
CMyThread(); // protected constructor used by dynamic creation
virtual ~CMyThread();

public:
// Used to pass the socket handle from the main thread to this thread.
SOCKET m_hSocket;

// CSocket derived class that handles the connection.
CSock m_socket;

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyThread)
public:
virtual BOOL InitInstance();
virtual int ExitInstance();
virtual int Run();
//}}AFX_VIRTUAL
};





// CMyThread class: MyThread.cpp
#include "MyThread.h"

IMPLEMENT_DYNCREATE(CMyThread, CWinThread)

CMyThread::CMyThread()
{
m_bAutoDelete = TRUE;
}

CMyThread::~CMyThread()
{
}

BOOL CMyThread::InitInstance()
{
:
:

// Attach the socket handle to a CSocket object.
m_socket.Attach(m_hSocket);
m_socket.m_pThread = this;

:
:

return TRUE;
}

int CMyThread::ExitInstance()
{
m_socket.ShutDown();
m_socket.Close();

:
:

return CWinThread::ExitInstance();
}

int CMyThread::Run()
{
// TODO: Add your specialized code here and/or call the base class
PostQuitMessage(0);
return CWinThread::Run();
}

AnswerRe: Multithreaded server application - increase in application memory usage Pin
Mr.Brainley13-Sep-06 23:08
Mr.Brainley13-Sep-06 23:08 
AnswerRe: Multithreaded server application - increase in application memory usage Pin
Mr.Brainley13-Sep-06 23:09
Mr.Brainley13-Sep-06 23:09 
Questionpopping up a window Pin
narayanagvs13-Sep-06 19:51
narayanagvs13-Sep-06 19:51 
AnswerRe: popping up a window Pin
_AnsHUMAN_ 13-Sep-06 20:40
_AnsHUMAN_ 13-Sep-06 20:40 
QuestionHow to subclass a Messgebox Pin
LiYS13-Sep-06 19:36
LiYS13-Sep-06 19:36 
AnswerRe: How to subclass a Messgebox Pin
_AnsHUMAN_ 13-Sep-06 19:39
_AnsHUMAN_ 13-Sep-06 19:39 
GeneralRe: How to subclass a Messgebox Pin
LiYS13-Sep-06 20:03
LiYS13-Sep-06 20:03 
GeneralRe: How to subclass a Messgebox Pin
_AnsHUMAN_ 13-Sep-06 20:12
_AnsHUMAN_ 13-Sep-06 20:12 
GeneralRe: How to subclass a Messgebox Pin
LiYS13-Sep-06 20:08
LiYS13-Sep-06 20:08 
GeneralRe: How to subclass a Messgebox Pin
_AnsHUMAN_ 13-Sep-06 20:15
_AnsHUMAN_ 13-Sep-06 20:15 
GeneralRe: How to subclass a Messgebox Pin
LiYS13-Sep-06 21:51
LiYS13-Sep-06 21:51 
GeneralRe: How to subclass a Messgebox Pin
_AnsHUMAN_ 13-Sep-06 22:02
_AnsHUMAN_ 13-Sep-06 22:02 
AnswerRe: How to subclass a Messgebox Pin
Hamid_RT13-Sep-06 23:03
Hamid_RT13-Sep-06 23:03 
QuestionShow CWnd as active when not selected Pin
NorGUI13-Sep-06 19:18
NorGUI13-Sep-06 19:18 
QuestionAssertion Error while creating dialog box Pin
gloriousgopi13-Sep-06 18:45
gloriousgopi13-Sep-06 18:45 
QuestionRe: Assertion Error while creating dialog box Pin
prasad_som13-Sep-06 19:02
prasad_som13-Sep-06 19:02 
AnswerRe: Assertion Error while creating dialog box Pin
Hamid_RT13-Sep-06 19:22
Hamid_RT13-Sep-06 19:22 

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.