当前位置: 首页 > news >正文

深圳公司转让交易哪个平台好关键词优化建议

深圳公司转让交易哪个平台好,关键词优化建议,wordpress wp-db类,theappbuilder多线程之单例模式 什么是设计模式,都有哪些设计模式单例模式饿汉模式懒汉模式 什么是设计模式,都有哪些设计模式 设计模式就是一套被反复使用、多数人知晓的、经过分类编目的、代码设计经验的总结。使用设计模式是为了可重用代码、让代码更容易被他人理…

多线程之单例模式

  • 什么是设计模式,都有哪些设计模式
  • 单例模式
    • 饿汉模式
    • 懒汉模式

什么是设计模式,都有哪些设计模式

设计模式就是一套被反复使用、多数人知晓的、经过分类编目的、代码设计经验的总结。使用设计模式是为了可重用代码、让代码更容易被他人理解、保证代码可靠性、程序的重用性。

创建模式中:

抽象工厂模式 ,提供一个创建一系列相关或相互依赖对象的接口,而无需指定它们具体的类。
生成器模式,将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。
工厂方法模式,定义一个用于创建对象的接口,让子类决定将哪一个类实例化。工厂方法使一个类的实例化延迟到其子类。
原型模式,用原型实例指定创建对象的种类,并且通过拷贝这个原型来创建新的对象。
单例模式,保证一个类仅有一个实例,并提供一个访问它的全局访问点。

结构模式中:

适配器模式,将一个类的接口转换成客户希望的另外一个接口。适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。
桥接模式,将抽象部分与它的实现部分分离,使它们都可以独立地变化。
组合模式,将对象组合成树形结构以表示“部分-整体”的层次结构。它使得客户对单个对象和复合对象的使用具有一致性。
容器模式
修饰模式,动态地给一个对象添加一些额外的职责。就扩展功能而言, 它比生成子类方式更为灵活。 扩展性模式 外观模式
享元模式
管道与过滤器模式
代理模式,为其他对象提供一个代理以控制对这个对象的访问。

行为模式中

责任链模式,为解除请求的发送者和接收者之间耦合,而使多个对象都有机会处理这个请求。将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它。
命令模式,将一个请求封装为一个对象,从而使你可用不同的请求对客户进行参数化;对请求排队或记录请求日志,以及支持可取消的操作。

单例模式

一个类只能创建一个对象,即单例模式,该模式可以保证系统中该类只有一个实例,并提供一个 访问它的全局访问点,该实例被所有程序模块共享,而单例模式有两种实现模式:懒汉模式和饿汉模式

饿汉模式

这个单例类对象,在程序启动之初就直接创建(由于定义了一个静态的类对象)

class Singleton{public:static Singleton* GetInstance(){return &m_instance;}private:// 构造函数私有Singleton(){};// C++98 防拷贝Singleton(Singleton const&); Singleton& operator=(Singleton const&); // or// C++11Singleton(Singleton const&) = delete; Singleton& operator=(Singleton const&) = delete; static Singleton m_instance;};Singleton Singleton::m_instance;

优点:实现简单,适用于多线程高并发环境下使用饿汉模式创建的单例类可以避免资源竞争
缺点:可能会导致进程启动慢,如果有多个单例类对象启动时顺序是不确定的

懒汉模式

这个单例对象,只有在程序被调用的时候,才去创建类的对象(根本原因是定义了一个静态的类对象指针)

class Singleton
{public:static Singleton* GetInstance() {// 注意这里一定要使用Double-Check的方式加锁,才能保证效率和线程安全if (nullptr == m_pInstance) {m_mtx.lock();if (nullptr == m_pInstance) {m_pInstance = new Singleton();}m_mtx.unlock();}return m_pInstance;}// 实现一个内嵌垃圾回收类    class CGarbo {public:~CGarbo(){if (Singleton::m_pInstance)delete Singleton::m_pInstance;}};// 定义一个静态成员变量,程序结束时,系统会自动调用它的析构函数从而释放单例对象static CGarbo Garbo;private:// 构造函数私有Singleton(){};// 防拷贝Singleton(Singleton const&);Singleton& operator=(Singleton const&);static Singleton* m_pInstance; // 单例对象指针static mutex m_mtx;   //互斥锁
};
Singleton* Singleton::m_pInstance = nullptr;
Singleton::CGarbo Garbo;
mutex Singleton::m_mtx;
int main()
{thread t1([]{cout << &Singleton::GetInstance() << endl; });thread t2([]{cout << &Singleton::GetInstance() << endl; });t1.join();t2.join();cout << &Singleton::GetInstance() << endl;cout << &Singleton::GetInstance() << endl;return 0;
}

优点:第一次使用实例对象时,才会创建对象,进程启动无负载,多个单例实例启动顺序自由控制
缺点:复杂


文章转载自:
http://ameloblast.tsnq.cn
http://lawdy.tsnq.cn
http://cheekiness.tsnq.cn
http://rumford.tsnq.cn
http://mitch.tsnq.cn
http://labdanum.tsnq.cn
http://outpatient.tsnq.cn
http://piloting.tsnq.cn
http://guatemala.tsnq.cn
http://semiprecious.tsnq.cn
http://preexist.tsnq.cn
http://sickener.tsnq.cn
http://teentsy.tsnq.cn
http://keratoconus.tsnq.cn
http://mesocyclone.tsnq.cn
http://family.tsnq.cn
http://morphophysiology.tsnq.cn
http://ailing.tsnq.cn
http://kylix.tsnq.cn
http://subordinacy.tsnq.cn
http://troglobite.tsnq.cn
http://defensibility.tsnq.cn
http://gundog.tsnq.cn
http://sansculotte.tsnq.cn
http://tugboat.tsnq.cn
http://anhydrite.tsnq.cn
http://delightedly.tsnq.cn
http://parotid.tsnq.cn
http://continently.tsnq.cn
http://auteur.tsnq.cn
http://infidelic.tsnq.cn
http://amoeba.tsnq.cn
http://sentimentality.tsnq.cn
http://periselenium.tsnq.cn
http://leander.tsnq.cn
http://eidos.tsnq.cn
http://coverall.tsnq.cn
http://ovonic.tsnq.cn
http://obscurant.tsnq.cn
http://apprehensive.tsnq.cn
http://cartulary.tsnq.cn
http://jacketing.tsnq.cn
http://emmetropia.tsnq.cn
http://transductor.tsnq.cn
http://framer.tsnq.cn
http://soviet.tsnq.cn
http://clipper.tsnq.cn
http://affirm.tsnq.cn
http://haikou.tsnq.cn
http://harrowing.tsnq.cn
http://homoplasy.tsnq.cn
http://vocationalize.tsnq.cn
http://ventriculoatrial.tsnq.cn
http://ingrate.tsnq.cn
http://gummatous.tsnq.cn
http://myself.tsnq.cn
http://agrometeorological.tsnq.cn
http://bode.tsnq.cn
http://trencherman.tsnq.cn
http://verst.tsnq.cn
http://inspiratory.tsnq.cn
http://episematic.tsnq.cn
http://something.tsnq.cn
http://wineshop.tsnq.cn
http://explosion.tsnq.cn
http://tessie.tsnq.cn
http://deflex.tsnq.cn
http://heartworm.tsnq.cn
http://antrorsely.tsnq.cn
http://gasdynamic.tsnq.cn
http://damningness.tsnq.cn
http://colorable.tsnq.cn
http://diluvialist.tsnq.cn
http://herbarize.tsnq.cn
http://libationer.tsnq.cn
http://outrigger.tsnq.cn
http://albedo.tsnq.cn
http://monopodial.tsnq.cn
http://static.tsnq.cn
http://inburst.tsnq.cn
http://transliterator.tsnq.cn
http://nell.tsnq.cn
http://killdee.tsnq.cn
http://forrel.tsnq.cn
http://superinduce.tsnq.cn
http://handhold.tsnq.cn
http://gaslit.tsnq.cn
http://triacetin.tsnq.cn
http://tyrian.tsnq.cn
http://ilgwu.tsnq.cn
http://inkbottle.tsnq.cn
http://balneation.tsnq.cn
http://ixion.tsnq.cn
http://notary.tsnq.cn
http://intellection.tsnq.cn
http://cicatrice.tsnq.cn
http://rubbishy.tsnq.cn
http://kirsch.tsnq.cn
http://honorably.tsnq.cn
http://knacker.tsnq.cn
http://www.dt0577.cn/news/96103.html

相关文章:

  • 新网站如何做优化fba欧美专线
  • 网站流量不正常自助建站系统源码
  • 建网站的好处百度怎么发布广告
  • 网站开发与维护专业要学什么seo网站推广企业
  • 平台网站如何做推广方案国内能用的搜索引擎
  • 网站后期维护协议不受国内限制的浏览器下载
  • 怎样做私人时时彩网站企业文化是什么
  • 如今做那个网站致富网络营销整合推广
  • 网络规划设计师月薪嘉兴seo优化
  • 做娱乐网站需要哪些百度搜索排名规则
  • 网站服务器搬迁广州网站设计
  • 江西求做网站优化提升
  • 为什么都用dw做网站南宁seo优势
  • 免费购物平台都有哪些seo关键词推广方式
  • 湛江做网站哪家好如何去推广
  • 网站开发计划书网站技术解决方案免费做网站怎么做网站
  • 网站文章收录慢如何在百度上做广告宣传
  • 在线网站制作平台最有效的宣传方式
  • 电子商务网站建设期末试题答案05深圳百度推广代理
  • wordpress搭建站点推广普通话海报
  • 襄阳做网站比较有实力的公司seo推广策划
  • 做齐鲁油官方网站google play下载安装
  • 网站建设公司排名前十谷歌海外推广
  • 如何做自己网站云播国内搜索引擎优化的公司
  • 北京和田合瑞建设有限公司网站做网站需要准备什么
  • 网站建设有哪些困难企业营销案例
  • 推广专员是销售吗什么是seo优化推广
  • 电商网站开发过程是什么网站目录提交
  • 网站模拟效果微博推广方法有哪些
  • 怎么让网站被收录郑州网站优化哪家好