Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


singleton sharing issue with .dll


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 fstim82   Members   -  Reputation: 132

Like
0Likes
Like

Posted 28 February 2011 - 11:18 AM

I'm on a project where we've started with some false assumptions it seems. We / I'm new to .dlls and we've got a situation where we have a game.dll, and a gamelauncher.exe. We have singleton pattern style "managers", like a GraphicsManager, which we wanted to share between the laucher, and the game, but it seems the launcher and the game each have their own static memory, so I'd instantiate another instance gameside when calling GetInstance(). This isn't what we want. I could pass a pointer to the managers gameside, to use the original, but then I still run the risk of someone calling GetInstance when we don't really want them to. Should we get rid of singletons altogether and pass pointers, or should I do some kind of weird checking in the getInstances to query the launcher/game classes to get a single instance from the launcher? Design questions everywhere...

And can anyone tell me if passing pointers would even work? I've yet to try it just yet. I'm assuming I'm working in the same address space...

Sponsor:

#2 Antheus   Members   -  Reputation: 2405

Like
0Likes
Like

Posted 28 February 2011 - 12:10 PM

As soon as DLLs are involved, you're almost guaranteed to have a static initialization order fiasco.

An exe can include a DLL.
A DLL cannot include an exe.

So why not just declare the singletons as globals and manually initialize them in main()?

Lazy initialization comes from a completely different world, mostly enterprise and it even failed to serve those needs so IOC and DI frameworks are used nowadays.

And why does stuff need to be shared. Just use separate processes. Launcher doesn't need to share address space. Why even have a launcher? Look at web - single interface, no installers and similar nonsense. Or Chrome, updates transparently in background, launches new version on restart.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS