Re: STL String bug?

Tech-Archive recommends: Fix windows errors by optimizing your registry



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
.



Relevant Pages

  • Re: Complex Specified Information - Pitman Formula
    ... between the reference string and the test string. ... I *know* what sequences actually exist or possibly could ... There are only test strings that you compare to ...
    (talk.origins)
  • Re: Complex Specified Information - Pitman Formula
    ... between the reference string and the test string. ... I *know* what sequences actually exist or possibly could ... There are only test strings that you compare to ...
    (talk.origins)
  • Re: Complex Specified Information - Pitman Formula
    ... you go out to analyze any other sequences. ... other reference you give. ... is it possible for a set of reference strings to miss a non- ... sequences is likely to be non-random in origin. ...
    (talk.origins)
  • Re: Complex Specified Information - Pitman Formula
    ... you go out to analyze any other sequences. ... other reference you give. ... is it possible for a set of reference strings to miss a non- ... sequences is likely to be non-random in origin. ...
    (talk.origins)
  • Re: closing DB connections
    ... subject to the circular reference problem, since it IS based on reference ... where the parent has a child collection, and the children have a parent ... You're right that many people don't think of cleaning up strings, ... Dim rs1 As Object ...
    (microsoft.public.access.adp.sqlserver)