singleton-cpp icon indicating copy to clipboard operation
singleton-cpp copied to clipboard

How to, info...

Open Dariusz1989 opened this issue 3 years ago • 2 comments

Hey

1st of all, thank you for this all-in-one example! I've been banging my head against a wall for 2 weeks now screaming and losing my mind with this,

In any case, any chance to get some more explanations? As far as I can tell we have 2 dlls made here, 1 singleton, 1 my_dll + both linked to my_exe as our app. Would this work too if we make these static libraries? Say:

  1. Static lib singleton
  2. Static lib backend framework - could be my_dll
  3. Exe (like u have) + link the 2 static-libs above
  4. Dll imported via HMODULE h=LoadLibrary(filename); at runtime ?
  5. Would singletons made in either static-libs, or exe or DLL then be all properly shared?

I'm still trying to wrap my head around it and what is needed/not needed depending on the lib static/shared system... But any comments/info would greatly help!

How would one go around deleting one singleton? for some crazy reason... TIA!

Thank you again for this lib! So far I'm @_@

Dariusz1989 avatar Dec 07 '21 23:12 Dariusz1989

Did more tests, everything works like a dream! Even dynamically importing dll & accessing singleton there! Best Lib Ever.

Dariusz1989 avatar Dec 08 '21 01:12 Dariusz1989

Thanks for liking this lib

  1. Static lib singleton
  2. Static lib backend framework - could be my_dll
  3. Exe (like u have) + link the 2 static-libs above
  4. Dll imported via HMODULE h=LoadLibrary(filename); at runtime ?

1-4,yes, it works

  1. Would singletons made in either static-libs, or exe or DLL then be all properly shared?

5, Yes, but singleton lib itself should be compiled into dll (singleton.dll on windows or libsingleton.so on linux).

How would one go around deleting one singleton? Not supported currently, a workaround may be --

struct MyDeletable {
    MyDeletable() 
        : obj(new MyObject) {
    }

    std::unique_ptr<MyObject> obj;
};

MyDeletable &deletable = singleton<MyDeletable>();

// use deletable.obj to access the object

deletable.obj.reset(); //delete the real object

xhawk18 avatar Dec 08 '21 11:12 xhawk18