Jump to content
  • Advertisement
Sign in to follow this  
dave

DLLs & Static Data

This topic is 3609 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I encountered a big gotcha with DLLs today, i have googled and failed to see any good explanation of appropriate practices for fixing it, so here goes: I have a DLL with alot of functionality in it, one of these pieces of functionality is the implementation of a class called Path. Following a tutorial i found on a good practice for DLLs, i have a 'parallel' project that provides IPath, this project builds to a static lib and is linked in other DLL projects so that they can use the interface. It is also linked in to the test application. Typical usage to get a path is like this:
IPath* pPathObject( GetDLLInterface()->CreatePath( "some path" ) );
Now IPath has a static std::map in it, this map stores symbols and replacement values, so you can do:
IPath::AddSymbolSubstition( "#SomeBasePath#", "C:/ActualPath" );
So then whenever you use that in a path it replaces it and you get the relative look up. The problem is, if i populate the map using AddSymbolSubstition (which is a static method populating a static object) in say WinMain and then use the IPath class within another DLL, wherever it is used that ISN'T where i initialised the map i don't have the entries i populated it with from WinMain. Now i understand why this is, but i am strugging to think of a suitable way to circumvent this. Is this simply a case of DON'T DO THIS? Any tips?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Dave
Following a tutorial i found on a good practice for DLLs, i have a 'parallel' project that provides IPath, this project builds to a static lib and is linked in other DLL projects so that they can use the interface.


This sounds very suspicious. If the static data you're dealing with is in the static lib, then every DLL and EXE will have a separate copy.

Share this post


Link to post
Share on other sites
Because it exactly matches the problem you're having, and to add insult to injury also required you to do extra work to get that problem.

Share this post


Link to post
Share on other sites
So is it simply a case of you cannot do what im trying to do at all when you are using DLLs? Do we just so no to static data entirely?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!