using std::string under CRT "Debug Multithreaded DLL"

using std::string under CRT "Debug Multithreaded DLL"

Post by Jeffre » Tue, 27 Jan 2004 13:32:42


his is a multi-part message in MIME format.


i'm building a simple win 32 dll and a MFC test exe components using the same run-time library (Debug Multithreaded DLL)
But once i do so, the EXE test client will got memory dumps

I found the suspected code which introcduce to the leak is using a
std::string structure member inside a static vector
Here's part of the code in the DLL:

In the .h
#include <vector>
#include <string>
class CBOSpread
{
public:
static struct SPREAD_DETAIL
{
//std::string strXchgId;
//std::string strMktId;
int iSymbolType;
};

typedef std::vector<SPREAD_DETAIL> SPREAD_DETAIL_LIST;

CBOSpread();
virtual ~CBOSpread();

static SPREAD_DETAIL_LIST m_vectSpreadTable;
};

in the cpp
CBOSpread::SPREAD_DETAIL_LIST CBOSpread::m_vectSpreadTable;

If i use std::string under "Debug Multithreaded DLL", there will be a leak
However, If i comment out the two line std::string strXchgId and std::string strMktId,
everyting will be fine even under "Debug Multithreaded DLL"

If i am using CRT "Debug Multithreaded" there won't be any problem, no matter if using std:string or not
but i have to put them under CRT "Debug Multithreaded DLL" for passing heap allocated items across the
EXE/DLL boundary

Could anyone know the reasons ?
Or shall i use char[] instead of str::string ?
I'm using Visual C++ 6.0 SP5
thx for kindly help

Jeffrey

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=big5">
<META content="MSHTML 6.00.2800.1276" name=GENERATOR>
<STYLE></STYLE>
</HEAD><FONT face=Arial><FONT size=2>
<BODY>
<DIV>i'm building a simple win 32 dll and a MFC test exe components
using the same run-time library (Debug Multithreaded DLL)<BR>But once i do so,
the EXE test client will got memory dumps<BR><BR>I found the suspected code
which introcduce to the leak is using a<BR>std::string structure member inside a
static vector<BR>Here's part of the code in the DLL:<BR><BR>In the
..h<BR>#include <vector><BR>#include <string><BR>class
CBOSpread<BR>{<BR>public:<BR>    static struct
SPREAD_DETAIL<BR>   
{<BR>        //std::string
strXchgId;<BR>        //std::string
strMktId;<BR>       
int         iSymbolType;</DIV>
<DIV>    };<BR><BR>    typedef
std::vector<SPREAD_DETAIL>
SPREAD_DETAIL_LIST;<BR><BR>CBOSpread();<BR>virtual
~CBOSpread();<BR><BR> static SPREAD_DETAIL_LIST
m_vectSpreadTable;<BR>};<BR><BR>in the cpp<BR>CBOSpread::SPREAD_DETAIL_LIST
CBOSpread::m_vectSpreadTable;<BR><BR>If i use std::string under "Debug
Multithreaded DLL", there will be a leak<BR>However, If i comment out the two
line std::string strXchgId and std::string strMktId,<BR>everyting will be fine
even under "Debug Multithreaded DLL"</DIV>
<DIV><BR>If i am using CRT "Debug Multithreaded" there won't be any problem, no
 
 
 

using std::string under CRT "Debug Multithreaded DLL"

Post by Jeffre » Tue, 27 Jan 2004 18:06:25

his is a multi-part message in MIME format.


It really doubt me even if i create a simple win32 DLL with just one function call
Once i changed its CRT to "Debug Multithreaded DLL" and using std::string
it will introduce object dumps

My simple DLL :
#include "stdafx.h"
#include <string>
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{ return TRUE;
}

DWORD __declspec(dllexport) ITInitDBAccess()
{
std::string stra;
std::string strb;
stra = "AAA";
return 0;
}

Detected memory leaks!
Dumping objects ->
{42} normal block at 0x00342638, 33 bytes long.
Data: < C > 00 43 00 CD CD CD CD CD CD CD CD CD CD CD CD CD
{41} normal block at 0x003425D0, 40 bytes long.
Data: < |L > 14 7C 4C 10 16 00 00 00 00 00 00 00 00 00 00 00

would anyone know why or how to slove please kind help

Jeffrey
"Jeffrey" < XXXX@XXXXX.COM > wrote in message news: XXXX@XXXXX.COM ...
i'm building a simple win 32 dll and a MFC test exe components using the same run-time library (Debug Multithreaded DLL)
But once i do so, the EXE test client will got memory dumps

I found the suspected code which introcduce to the leak is using a
std::string structure member inside a static vector
Here's part of the code in the DLL:

In the .h
#include <vector>
#include <string>
class CBOSpread
{
public:
static struct SPREAD_DETAIL
{
//std::string strXchgId;
//std::string strMktId;
int iSymbolType;
};

typedef std::vector<SPREAD_DETAIL> SPREAD_DETAIL_LIST;

CBOSpread();
virtual ~CBOSpread();

static SPREAD_DETAIL_LIST m_vectSpreadTable;
};

in the cpp
CBOSpread::SPREAD_DETAIL_LIST CBOSpread::m_vectSpreadTable;

If i use std::string under "Debug Multithreaded DLL", there will be a leak
However, If i comment out the two line std::string strXchgId and std::string strMktId,
everyting will be fine even under "Debug Multithreaded DLL"

If i am using CRT "Debug Multithreaded" there won't be any problem, no matter if using std:string or not
but i have to put them under CRT "Debug Multithreaded DLL" for passing heap allocated items across the
EXE/DLL boundary

Could anyone know the reasons ?
Or shall i use char[] instead of str::string ?
I'm using Visual C++ 6.0 SP5
thx for kindly help

Jeffrey

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=big5">
<META content="MSHTML 6.00.2800.1276" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>It really doubt me even if i create a simple win32
DLL with just one function call</FONT></DIV>
<DIV><FONT face=Arial size=2>Once i changed its CRT to "Debug Multithreaded DLL"
and using std::string</FONT></DIV>
<DIV><FONT face=Arial size=2>it will introduce object dumps</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>My simple DLL :</FONT></DIV>
<DIV><FONT face=Arial size=2>#include "stdafx.h"<BR>#include
<string><BR>BOOL
 
 
 

using std::string under CRT "Debug Multithreaded DLL"

Post by Stephen Ho » Fri, 30 Jan 2004 03:04:40

Thank you very much for yr reply.
I've further analyst the problem and found that the leak
only happened in MFC Client (under Project Setting-> C/C++ tab -> Code
Generation, use Debug Multithreaded DLL )

I would go and check that debug project for your MFC Client is using Debug
MultiThreaded DLL. I would also check that the release project is using
MultiThreaded DLL. You will probably find that one DLL is built using
different settings and that is what is screwing you up.

Stephen Howe