Re: STL String bug?
- From: "Tom Widmer [VC++ MVP]" <tom_usenet@xxxxxxxxxxx>
- Date: Wed, 15 Mar 2006 13:41:47 +0000
David Wilkinson wrote:
Tom Widmer [VC++ MVP] wrote:
George wrote:
Visual Studio 6 Service Pack 5.
All,
Below is some Dr.Watson output from our server application which seems
to randomly crash indicating some sort of STL string problem. I am aware of
the dinkumware fixes but have been reluctant to apply these until certain
that the lack of a fix is the cause. STL strings are passed across DLL
boundaries but I am sure the CRT linkage is consistent throughout and
typically the strings are only read or copied.
In addition to Stephen's reply:
Copying is a potential problem, since under VC6, std::basic_string is reference counted and hence copies aren't real copies (and hence you may end up destroying the characters of a string on the other side of the DLL boundary). I believe the fixes you mention address this by telling you how to disable reference counting...
Tom
Tom:
But these fixes do not take effect unless you rebuild MSVCP60.DLL. See the other recent thread started by Andreas Fabri.
True (and upgrading to a newer VC or buying the Dinkumware upgrade library is probably the best solution in the absence of an SP fix). A workaround to avoid having to rebuild is to force unsharing of strings:
__declspec(dllimport) std::string const& dllFunc();
std::string s(dllFunc());
s[0]; //forces unshare and makes a local copy of the string.
It is only safe to pass/return const references, and to immediately unshare any copies made. Ideally, std::string shouldn't be used at all in a DLL interface, since it introduces a dependency on a particular compiler and library version.
Tom
.
- References:
- STL String bug?
- From: George
- Re: STL String bug?
- From: Tom Widmer [VC++ MVP]
- Re: STL String bug?
- From: David Wilkinson
- STL String bug?
- Prev by Date: Re: Problem with reading an int with operator>>
- Next by Date: Re: Problem with reading an int with operator>>
- Previous by thread: Re: STL String bug?
- Next by thread: Re: Overly aggressive checking in new STL (Visual Studio 2005)?
- Index(es):
Relevant Pages
|