std::map.find() crashing in DLL 
Author Message
 std::map.find() crashing in DLL

I'm seeing a big problem that I'm trying to fully understand in order
to fix my current problem and avoid similar issues in the future. In
brief it is this:

I have an object 'foo' implmented in my client (exe) which holds an
std::map<long,std::string>. The map is populated with entries at
construction. The constructor takes a string (a comma-separated
key-value set), parses the string, fills the map via the [] operator
-- foo also holds onto the original string in a member variable:

// statically linked into the exe

class Foo {
  Foo(std::string&); // parses the string and fills the map
  Foo(foo const &);  // gets the original string from the parameter
                     //  and fills the map
  ~Foo();

  std::string GetValueFromKey(long); // return value from map for
given key

  std::map<long,std::string> myMap;
  std::string originalString;

Quote:
};

In DLL #1, I create an instance of foo with a string and pass a
reference to that foo object into another object (bar) created and
owned by another DLL, but to which I have a pointer:

Foo aFoo("1=A,2=B,3=C");
pBar->SomeFunc(aFoo);

In DLL #2, the Bar object has a function which uses map.find():

Bar::SomeFunc(Foo& inFoo) {
  std::string value = inFoo->GetValueFromKey(1);

Quote:
}

The call to map.find() causes a memory exception. I need to know why.
I've found a work-around, but it involves shuffling around where I
create the foo object and how I pass it around. I assume the problem
is due to the fact that I'm passing a reference created in one DLL
into another DLL, but why?

It appears as though the map is getting FUBARed, but the std::string
member variable remains valid?

At first, I thought that perhaps I was using multiple heaps, but in my
project settings, all my DLLs and the client EXE are set to "Debug
Multithreaded DLL" and "Multithreaded DLL" for debug and release,
respectively. So I don't *think* that's the problem.

Anyone know what's going on here?



Tue, 05 Apr 2005 03:01:35 GMT  
 std::map.find() crashing in DLL
See http://www.dinkumware.com/vc_fixes.html , in particular Fix to
<xtree>
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> I'm seeing a big problem that I'm trying to fully understand in order
> to fix my current problem and avoid similar issues in the future. In
> brief it is this:

> I have an object 'foo' implmented in my client (exe) which holds an
> std::map<long,std::string>. The map is populated with entries at
> construction. The constructor takes a string (a comma-separated
> key-value set), parses the string, fills the map via the [] operator
> -- foo also holds onto the original string in a member variable:

> // statically linked into the exe

> class Foo {
>   Foo(std::string&); // parses the string and fills the map
>   Foo(foo const &);  // gets the original string from the parameter
>                      //  and fills the map
>   ~Foo();

>   std::string GetValueFromKey(long); // return value from map for
> given key

>   std::map<long,std::string> myMap;
>   std::string originalString;
> };

> In DLL #1, I create an instance of foo with a string and pass a
> reference to that foo object into another object (bar) created and
> owned by another DLL, but to which I have a pointer:

> Foo aFoo("1=A,2=B,3=C");
> pBar->SomeFunc(aFoo);

> In DLL #2, the Bar object has a function which uses map.find():

> Bar::SomeFunc(Foo& inFoo) {
>   std::string value = inFoo->GetValueFromKey(1);
> }

> The call to map.find() causes a memory exception. I need to know why.
> I've found a work-around, but it involves shuffling around where I
> create the foo object and how I pass it around. I assume the problem
> is due to the fact that I'm passing a reference created in one DLL
> into another DLL, but why?

> It appears as though the map is getting FUBARed, but the std::string
> member variable remains valid?

> At first, I thought that perhaps I was using multiple heaps, but in my
> project settings, all my DLLs and the client EXE are set to "Debug
> Multithreaded DLL" and "Multithreaded DLL" for debug and release,
> respectively. So I don't *think* that's the problem.

> Anyone know what's going on here?



Tue, 05 Apr 2005 04:00:08 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing std::set and std::map objects between 2 dlls

2. Exporting STL containers (specifically std::map) from DLL?

3. MFC Extension DLL and std::map

4. mem leaks when using std::map in a dll

5. std::map compiler stack overflow when DLL

6. passing std::map based objects from an app to a dll

7. std::vector crash using with DLL?

8. export classes using std namespace (ex std::vector) in a DLL

9. any sample of std::map as global

10. Help needed on std::map<>

11. Error using Microsoft's implementation of std::map

12. STL, std::allocator and memory mapped files

 

 
Powered by phpBB® Forum Software