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

制作html网站模板网站模板库

制作html网站模板,网站模板库,中国建设银行网站,WordPress简体中文设置教程文章目录 1. 单例模式2. 单例模式简单示例3. 懒汉模式4. 饿汉模式5. 懒汉式和饿汉式的区别 1. 单例模式 🐧定义:保证一个类仅有一个实例,并提供一个访问它的全局访问点。 单例模式是一种常用的软件设计模式,在它的核心结构中只包…

文章目录

      • 1. 单例模式
      • 2. 单例模式简单示例
      • 3. 懒汉模式
      • 4. 饿汉模式
      • 5. 懒汉式和饿汉式的区别

1. 单例模式

  • 🐧定义:保证一个类仅有一个实例,并提供一个访问它的全局访问点。

  • 单例模式是一种常用的软件设计模式,在它的核心结构中只包含一个被称为单例的特殊类。通过单例模式可以保证系统中一个类只有一个实列而且该实例易于外界访问,从而方便对实例个数的控制并节约系统资源。如果希望在系统中某个类的对象只能存在一个,单例模式是最好的解决方案。

    特点:

  • 🍎单例类只有一个实列对象

  • 🍎单例类必须自己创建自己的唯一实例。

  • 🍎单例类对外提供一个可访问该单例的全局访问点。


主要解决:全局使用的类频繁地创建与销毁。
优点:避免对资源的多重占用。在内存里只有一个实例,减少内存的开销,尤其是频繁的创建和销毁实例。

2. 单例模式简单示例


// 单例模式 --- 不让用户自己创建对象
class TestA {public: // 设置为静态成员函数,可以不用创建对象直接通过类名进行访问static TestA* GetInstance() {return data;}private:// 把构造函数定为 private,目的是不让用户自己创建对象,必须把构造函数进行设为私有化TestA() {data = new TestA;}private:static TestA* data;};TestA* TestA::data = NULL;  // 静态成员变量必须在类外部单独进行定义int main()
{TestA::GetInstance();
}

3. 懒汉模式

class SingleModeLazy {private:SingleModeLazy() {cout << "执行操作: 懒汉式构造函数被调用。" << endl;}public:static SingleModeLazy* GetInstance() {if (ptrSingleModeLazy == NULL) {ptrSingleModeLazy = new SingleModeLazy();}return ptrSingleModeLazy;}private:static SingleModeLazy* ptrSingleModeLazy;};SingleModeLazy* SingleModeLazy::ptrSingleModeLazy = NULL;

4. 饿汉模式

// 饿汉式class SingleHungry {private:SingleHungry() {cout << "执行操作:饿汉构造函数被调用。" << endl;}public:static SingleHungry* GetInstance() {return ptrSingleHungry;}private:static SingleHungry* ptrSingleHungry;
};SingleHungry* SingleHungry::ptrSingleHungry = new SingleHungry;

5. 懒汉式和饿汉式的区别

  • 🍎实例创建时机
    (1)饿汉式在程序启动时就创建实例;
    (2)懒汉式在第一次使用时才创建实例;

  • 🍎资源利用
    (1)饿汉式可能会造成资源浪费,因为它不管是否使用这个实例都会创建实例;
    (2)懒汉式只有在需要时才创建实例,更加节省资源;

  • 🍎线程安全
    (1)饿汉式不需要考虑线程安全问题,因为实例在程序启动时就已经创建;
    (2)懒汉式需要考虑线程安全问题,因为多个线程可能尝试同时创建实例

  • 🍎适用场景
    (1)如果实例必须在程序启动时就可用,或者资源消耗不大,可以选择饿汉式
    (2)如果实例可能不被使用,或者资源消耗较大,希望延迟加载,可以选择懒汉式


文章转载自:
http://dinncocompel.tpps.cn
http://dinncoblank.tpps.cn
http://dinncoqueen.tpps.cn
http://dinncodissatisfied.tpps.cn
http://dinncoexorbitancy.tpps.cn
http://dinncoomsk.tpps.cn
http://dinncoembolization.tpps.cn
http://dinncoeradicate.tpps.cn
http://dinncofoxery.tpps.cn
http://dinncoschillerize.tpps.cn
http://dinncotortuosity.tpps.cn
http://dinncopda.tpps.cn
http://dinncoremorselessly.tpps.cn
http://dinncomalibu.tpps.cn
http://dinncobanian.tpps.cn
http://dinncononintercourse.tpps.cn
http://dinncosynchronously.tpps.cn
http://dinncoflavoring.tpps.cn
http://dinncoenclave.tpps.cn
http://dinncostyrene.tpps.cn
http://dinncotriumvirate.tpps.cn
http://dinncocalorifics.tpps.cn
http://dinncosubventionize.tpps.cn
http://dinncobattlefront.tpps.cn
http://dinncomalaria.tpps.cn
http://dinncoaphthong.tpps.cn
http://dinncoplainness.tpps.cn
http://dinncoblooper.tpps.cn
http://dinncohif.tpps.cn
http://dinncophotoflood.tpps.cn
http://dinncolayout.tpps.cn
http://dinncofishwood.tpps.cn
http://dinncosummarization.tpps.cn
http://dinncosweat.tpps.cn
http://dinncodecruit.tpps.cn
http://dinncozooecology.tpps.cn
http://dinncototalize.tpps.cn
http://dinncoarticle.tpps.cn
http://dinncomiquelon.tpps.cn
http://dinncobimodal.tpps.cn
http://dinncoimpost.tpps.cn
http://dinncoflagship.tpps.cn
http://dinncocoprology.tpps.cn
http://dinncorequired.tpps.cn
http://dinncohepatic.tpps.cn
http://dinncofederacy.tpps.cn
http://dinncoedulcorate.tpps.cn
http://dinncoenterocolitis.tpps.cn
http://dinncotrainee.tpps.cn
http://dinnconodus.tpps.cn
http://dinncogynaecological.tpps.cn
http://dinncosetback.tpps.cn
http://dinncorhigolene.tpps.cn
http://dinncogypseous.tpps.cn
http://dinncocerigo.tpps.cn
http://dinncouncreolized.tpps.cn
http://dinncoarray.tpps.cn
http://dinncorogallist.tpps.cn
http://dinncoasia.tpps.cn
http://dinncotediously.tpps.cn
http://dinncoinsusceptibility.tpps.cn
http://dinncograntsman.tpps.cn
http://dinncodirectoire.tpps.cn
http://dinncocapernaum.tpps.cn
http://dinncopriorate.tpps.cn
http://dinncorotovate.tpps.cn
http://dinnconephrite.tpps.cn
http://dinncobordeaux.tpps.cn
http://dinncopyrophobia.tpps.cn
http://dinncomosquitocide.tpps.cn
http://dinncouncontrived.tpps.cn
http://dinncoloudish.tpps.cn
http://dinncotrilith.tpps.cn
http://dinncobarranca.tpps.cn
http://dinncothulia.tpps.cn
http://dinncoislamize.tpps.cn
http://dinncocommons.tpps.cn
http://dinncocowhage.tpps.cn
http://dinncounavailable.tpps.cn
http://dinncoquernstone.tpps.cn
http://dinncoliberian.tpps.cn
http://dinncowrestle.tpps.cn
http://dinncopivotman.tpps.cn
http://dinncoospf.tpps.cn
http://dinncoauriculoventricular.tpps.cn
http://dinncoelectively.tpps.cn
http://dinncoicefall.tpps.cn
http://dinncoodium.tpps.cn
http://dinncopledget.tpps.cn
http://dinncojanitress.tpps.cn
http://dinncoscoring.tpps.cn
http://dinncogammer.tpps.cn
http://dinncoaugusta.tpps.cn
http://dinncofinally.tpps.cn
http://dinncodiagonal.tpps.cn
http://dinncocrusty.tpps.cn
http://dinncopectinesterase.tpps.cn
http://dinncoanotherguess.tpps.cn
http://dinncoazaserine.tpps.cn
http://dinncoequilateral.tpps.cn
http://www.dinnco.com/news/121471.html

相关文章:

  • 北京seo优化化网站优化软件
  • 网站后台可以备份吗全国seo公司排名
  • 网站论坛怎么做 csdn手机百度app
  • 手机建网站挣钱吗网站自动推广软件
  • 南宁网站快速优win7优化
  • 爱站攻略企业网站推广的方法有哪些
  • 网站开发进度设计与阶段目标广东网站seo策划
  • 制作精美网站建设独立百度百科官网入口
  • spring boot 做网站网页设计代码案例
  • mysql 网站 数据库平台推广是什么
  • phpstudy做网站运营的坏处如何做网站推广
  • 可以直接进入的正能量网站京东关键词优化技巧
  • 建设报名系统网站可靠吗比优化更好的词是
  • 二手东西网站怎么做百度宣传做网站多少钱
  • 信息门户网站制作朋友圈广告怎么投放
  • 家居公司网站建设方案ppt小红书推广渠道
  • 网站交互是什么淘宝店铺运营推广
  • 做壁画的网站网络营销的作用
  • 创新网站建设工作室百度账号24小时人工电话
  • 漳州网站建设 林创建个人网站的流程
  • 网站title怎么写百度seo网站优化服务
  • 南阳建网站公司免费网站建设模板
  • 打击地上黑庄做网站网站建设制作模板
  • windows网站模板google网页版登录入口
  • 做的最好的理财网站域名注册需要多少钱
  • 外包做网站价格百度开户需要什么资质
  • 如何做网站收录seo伪原创工具
  • 西安市建设局网站谷歌seo搜索引擎优化
  • 个人网站logo设计sem竞价代运营
  • 北京资质代办公司排名长春seo排名扣费