singleton-cpp
singleton-cpp copied to clipboard
How to, info...
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:
- Static lib singleton
- Static lib backend framework - could be my_dll
- Exe (like u have) + link the 2 static-libs above
- Dll imported via HMODULE h=LoadLibrary(filename); at runtime ?
- 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 @_@
Did more tests, everything works like a dream! Even dynamically importing dll & accessing singleton there! Best Lib Ever.
Thanks for liking this lib
- Static lib singleton
- Static lib backend framework - could be my_dll
- Exe (like u have) + link the 2 static-libs above
- Dll imported via HMODULE h=LoadLibrary(filename); at runtime ?
1-4,yes, it works
- 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