kondeu / globalsingleton Goto Github PK
View Code? Open in Web Editor NEW一个进程空间内全局单例的框架(注册到独立外置的一个dll中),支持热加载/热卸载动态链接库。
License: MIT License
一个进程空间内全局单例的框架(注册到独立外置的一个dll中),支持热加载/热卸载动态链接库。
License: MIT License
GlobalSingleton 一个进程空间内全局单例的框架 - 支持动态库热加载/热卸载 Windows使用注意事项: 1. 要求使用MD/MDd,而不是MT/MTd,保证exe和所有dll间使用同一个crtheap堆,否则 exe和不同dll间都有各自的crtheap堆,而new和delete需要在同一堆中配套执行。 2. 慎用virtual,析构函数不能为virtual函数。因为当析构函数为virtual函数时,如果 单例由dll1加载,而dll2在dll1卸载之后如果还在使用,那析构时调virtual的析构函 数会去查虚函数表,而虚函数表是由dll1创建的,会引发崩溃。其他虚函数也涉及虚函 数表,因此若要使用虚函数,那么除非能保证dll的卸载顺序,否则不要使用热卸载。 事实上,全局单例的管理交由单例框架来实现后,析构函数是否使用virtual都不会产生 泄漏,因为单例框架构造和析构时使用的都是具体的全局单例类,而不会是它们的基类。 3. 单例全为懒加载,直到GetReference的时候才真正实例化单例对象,需要注意全局单例 没有保证多线程间安全,因此在单例实例化/动态库首次获取单例时都是线程不安全的。 若在SingletonManager.cpp的Count/Obtain/Release函数中使用std::mutex加锁能够实现 单例获取的安全,但实例化过程(创建过程)仍是线程不安全的。 C++版本要求:C++14 以上(MSVC v140 (VS2015) 以上,如果使用Visual Studio)。
typeid(T).hash_code在Android的部分编译器上同一个类型在不同的so中的hash_code会不同,会导致GlobalSingleton无法工作;
若最终的dll/so集合混用了不同类型、不同版本的编译器,可能会有hash_code不一致的潜在风险。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.