Click here to Skip to main content
16,008,010 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Thread func Pin
Tomasz Sowinski7-Aug-02 2:29
Tomasz Sowinski7-Aug-02 2:29 
GeneralRe: Thread func Pin
Daniel Lohmann7-Aug-02 3:24
Daniel Lohmann7-Aug-02 3:24 
GeneralRe: Thread func Pin
[CoY0te]7-Aug-02 2:36
[CoY0te]7-Aug-02 2:36 
GeneralRe: Thread func Pin
Daniel Lohmann7-Aug-02 3:30
Daniel Lohmann7-Aug-02 3:30 
GeneralBitmap Pin
anuprasad6-Aug-02 23:43
anuprasad6-Aug-02 23:43 
GeneralRe: Bitmap Pin
Tomasz Sowinski7-Aug-02 0:21
Tomasz Sowinski7-Aug-02 0:21 
GeneralAudio support Pin
jayostu6-Aug-02 23:01
jayostu6-Aug-02 23:01 
GeneralApplication Shutdown problem Pin
Anonymous6-Aug-02 22:52
Anonymous6-Aug-02 22:52 
The code below is a simple pool manager i written for pooling the VBScript
engines. I also created a CShirleyScriptSite COM:

<br />
class ATL_NO_VTABLE CShirleyScriptSite :<br />
 public CComObjectRootEx<CComMultiThreadModel>,<br />
 public CComCoClass<CShirleyScriptSite, &CLSID_ShirleyScriptSite>,<br />
 public IDispatchImpl<IShirleyScriptSite, &IID_IShirleyScriptSite,<br />
&LIBID_ShirleyLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,<br />
 public IActiveScriptSiteImpl,<br />
 public IActiveScriptSiteWindowImpl<br />
{<br />
 ... ...<br />
}<br />


I put into a MFC application 's MainFrame,
CComPoolManager<CComObject<cshirleyscriptsite&gt &gt="" m_scriptegr_pool;

in="" init="" instance,="" i="" called="" m_scriptegr_pool.createpoolobjects().="" when="" the
mainframe="" is
displayed,="" click="" the="" "x"="" button,="" then="" application="" should="" exits.
however,="" it="" is
still="" "run"="" in="" debugger,="" and="" ccompoolmanager's="" destructor="" seemed="" not
to="" be="" called.
anything="" wrong="" ?

if="" don't="" add="" line="" m_scriptegr_pool.createpoolobjects(),="" exits="" to
[design]="" mode
normally.="" can="" anyone="" show="" me="" night="" ?


<code="">
////////////////////////////////////////////////////////////////////////////
///////////////
//Function: CComPoolManager
//
//Description: A pool manager that does pooling of COM Objects. The
controlled objects (T)
// must be derived from CComObject<TypeName>.
//
//Usage: CComPoolManager<CComObject<CYourComClass> > m_my_pool;
////////////////////////////////////////////////////////////////////////////
///////////////
template <class T, int PZ = 10>
class CComPoolManager
{
public:

typedef std::deque<T*>::iterator iterator;

CComPoolManager() : m_pool_threshold(PZ)
{
TRACE("CComPoolManager constructor called\n");

InitializeCriticalSection(&m_cs);
}

~CComPoolManager()
{
TRACE("CComPoolManager destructor called\n");

iterator itr;
for(itr=m_free_list.begin();itr!=m_free_list.end();itr++)
{
(*itr)->Release();
}
m_free_list.clear();

DeleteCriticalSection(&m_cs);
}

//create default no. of objects
void CreatePoolObjects(int sz = PZ)
{
if (sz > PZ)
sz = PZ;

while(m_free_list.size() < sz)
{
T* pobj = NULL;

HRESULT hRes = T::CreateInstance(&pobj);
_ASSERTE(SUCCEEDED(hRes));

m_free_list.push_back(pobj);
}
}

void SetPoolThreshold(long thr)
{
m_pool_threshold = thr;
}

T* AllocateFromPool()
{
T* pobj = NULL;

EnterCriticalSection(&m_cs);

//allocate from the beginning of the list
iterator itr = m_free_list.begin();
if (itr != m_free_list.end())
{
pobj = *itr;
m_free_list.pop_front();
}
else
{
HRESULT hRes = T::CreateInstance(&pobj);
_ASSERTE(SUCCEEDED(hRes));

}
LeaveCriticalSection(&m_cs);

return pobj;
}

void ReturnToPool(T* pobj)
{
EnterCriticalSection(&m_cs);

if (m_free_list.size() > m_pool_threshold)
{
pobj->Release();
}
else
{
m_free_list.push_back(pobj);
}

LeaveCriticalSection(&m_cs);
}

private:

CRITICAL_SECTION m_cs;

std::deque<T*> m_free_list;

long m_pool_threshold;
};

GeneralCAsyncSocket Question Pin
Niko Tanghe6-Aug-02 22:48
Niko Tanghe6-Aug-02 22:48 
GeneralRe: CAsyncSocket Question Pin
Jon Hulatt7-Aug-02 1:47
Jon Hulatt7-Aug-02 1:47 
GeneralRe: CAsyncSocket Question Pin
Niko Tanghe7-Aug-02 1:55
Niko Tanghe7-Aug-02 1:55 
GeneralRe: CAsyncSocket Question Pin
Masaaki Onishi7-Aug-02 6:48
Masaaki Onishi7-Aug-02 6:48 
GeneralCLOCKS_PER_SEC Pin
Janette6-Aug-02 21:51
Janette6-Aug-02 21:51 
GeneralRe: CLOCKS_PER_SEC Pin
[CoY0te]6-Aug-02 23:45
[CoY0te]6-Aug-02 23:45 
GeneralRe: CLOCKS_PER_SEC Pin
_Magnus_6-Aug-02 23:47
_Magnus_6-Aug-02 23:47 
GeneralRe: CLOCKS_PER_SEC Pin
Haakon S.7-Aug-02 3:22
Haakon S.7-Aug-02 3:22 
GeneralLoading Bitmaps in Dialog Pin
Shibu6-Aug-02 21:40
Shibu6-Aug-02 21:40 
GeneralRe: Loading Bitmaps in Dialog Pin
Tomasz Sowinski7-Aug-02 0:25
Tomasz Sowinski7-Aug-02 0:25 
GeneralRe: Loading Bitmaps in Dialog Pin
Anonymous7-Aug-02 1:18
Anonymous7-Aug-02 1:18 
Generalmessagebox like dialogbox Pin
slah6-Aug-02 21:22
slah6-Aug-02 21:22 
GeneralRe: messagebox like dialogbox Pin
Tomasz Sowinski7-Aug-02 0:28
Tomasz Sowinski7-Aug-02 0:28 
GeneralIE View Source Data Pin
Paul M Watt6-Aug-02 21:05
mentorPaul M Watt6-Aug-02 21:05 
GeneralRe: IE View Source Data Pin
Paul M Watt7-Aug-02 6:46
mentorPaul M Watt7-Aug-02 6:46 
GeneralRe: How about Socket program? Pin
Masaaki Onishi7-Aug-02 7:09
Masaaki Onishi7-Aug-02 7:09 
GeneralRe: How about Socket program? Pin
Paul M Watt7-Aug-02 19:20
mentorPaul M Watt7-Aug-02 19:20 

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.