先看看介绍
// The LazyInstance<Type, Traits> class manages a single instance of Type,
// which will be lazily created on the first time it's accessed. This class is
// useful for places you would normally use a function-level static, but you
// need to have guaranteed thread-safety. The Type constructor will only ever
// be called once, even if two threads are racing to create the object. Get()
// and Pointer() will always return the same, completely initialized instance.
// When the instance is constructed it is registered with AtExitManager. The
// destructor will be called on program exit.
//
// LazyInstance is completely thread safe, assuming that you create it safely.
// The class was designed to be POD initialized, so it shouldn't require a
// static constructor. It really only makes sense to declare a LazyInstance as
// a global variable using the base::LinkerInitialized constructor.
//
// LazyInstance is similar to Singleton, except it does not have the singleton
// property. You can have multiple LazyInstance's of the same type, and each
// will manage a unique instance. It also preallocates the space for Type, as
// to avoid allocating the Type instance on the heap. This may help with the
// performance of creating the instance, and reducing heap fragmentation. This
// requires that Type be a complete type so we can determine the size.
//
// Example usage:
// static LazyInstance<MyClass> my_instance(base::LINKER_INITIALIZED);
// void SomeMethod() {
// my_instance.Get().SomeMethod(); // MyClass::SomeMethod()
//
// MyClass* ptr = my_instance.Pointer();
// ptr->DoDoDo(); // MyClass::DoDoDo
// }

1. 线程安全,构造成功后向AtExitManager注册,析构函数会在程序退出时调用

2. 类似Singleton,但是可以有多个同一个类型的LazyInstance,Singleton只能有一个类型的实例

3. POD https://akrzemi1.wordpress.com/2012/04/23/using-pods-in-c11/


引用了一个头文件

#include "base/dynamic_annotations.h"

参考分析chromium之dynamic_annotations,使用valgrind等动态分析工具,会影响最终生成的代码

下一个头文件

#include "base/at_exit.h"

参考分析chromium之at_exit,调用回调及单例的析构函数

												

chromium之lazy_instance的更多相关文章

  1. chromium之MessageLoop浅析

    对chromium的MessageLoop非常感兴趣,接下来会详细分析Windows平台的具体实现. 代码版本:chromium-4.0.210.0_p26329 先看一下依赖的文件 message_ ...

  2. Google之Chromium浏览器源码学习——base公共通用库(一)

    Google的优秀C++开源项目繁多,其中的Chromium浏览器项目可以说是很具有代表性的,此外还包括其第三开发开源库或是自己的优秀开源库,可以根据需要抽取自己感兴趣的部分.在研究.学习该项目前的时 ...

  3. QT5利用chromium内核与HTML页面交互

    在QT5.4之前,做QT开发浏览器只能选择QWebkit,但是有过使用的都会发现,这个webkit不是出奇的慢,简直是慢的令人发指,Release模式下还行,debug下你就无语了,但是webkit毕 ...

  4. 如何在windows上编译Chromium (CEF3) 并加入MP3支持(二)

    时隔一年,再次编译cef3,独一无二的目的仍为加入mp3支持.新版本的编译环境和注意事项都已经发生了变化,于是再记录一下. 一.编译版本 cef版本号格式为X.YYYY.A.gHHHHHHH X为主版 ...

  5. 如何在Windows上从源码编译Chromium (CEF3) 加入mp3支持

    一.什么是CEF CEF即Chromium Embeded Framework,由谷歌的开源浏览器项目Chromium扩展而来,可方便地嵌入其它程序中以得到浏览器功能. CEF包括CEF1和CEF3两 ...

  6. 构建基于Chromium的应用程序

    chromium是google chrome浏览器所采用的内核,最开始由苹果的webkit发展而出,由于webkit在发展上存在分歧,而google希望在开发上有更大的自由度,2013年google决 ...

  7. ubuntu中chromium无法播放flash,安装flash

    ubuntu14.0.4中系统自带的chromium无法播放flash,后来查了下,得知chromium已经不支持adobe flash了,用户可使用pepper flash替代.安装pepper f ...

  8. windows下编译chromium浏览器的15个流程整理

    编译chromium 系统为windows, 国内在windows上编译chromium的资料比较少, 我这篇文章只能作为参考, 记录我遇到的一些问题,因为chromium团队也会修改了代码,或者编译 ...

  9. Google之Chromium浏览器源码学习——base公共通用库(二)

    上次提到Chromium浏览器中base公共通用库中的内存分配器allocator,其中用到了三方库tcmalloc.jemalloc:对于这两个内存分配器,个人建议,对于内存,最好是自己维护内存池: ...

随机推荐

  1. 转动的八卦图纯css实现

      这类的东西网上一搜就是大把的,看着比较空旷的博客,所以自己也来写一个. <!DOCTYPE html> <html> <head> <meta chars ...

  2. 封装一个MPermissionsActivity的思路和步骤

    http://blog.csdn.net/longkehuawei/article/details/53202804 第一步:检测所有的权限是否都已授权 /** * 检测所有的权限是否都已授权 * * ...

  3. 新鲜出炉的Java开发者中心,约起来!

    入门教程.SDK 和工具推荐下载.操作方法指导.API 参考,Java 开发者需要的,这里应有尽有. ▼ 话说现在 Java 开发者在云端进行开发非常火热啊,「云+Java」就好比才子配佳人,真是难以 ...

  4. java中double类型显示两个小数,比如12.00

    Double类型的数据如何保留两位小数? 各位大虾,现有Double类型的数据,如何转换为保留两位小数的数,返回值的类型仍然是Double类型的,而不是字符串类型. 比如     0,返回“0.00” ...

  5. IT装B小技巧

    1.编写简单的关机脚本 新建一个文本文档,将代码复制上去,将后缀改成bat,双击运行 @echo off shutdown -s -t 2.语音播报 新建一个文本文档,将代码复制上去,将后缀改成vbs ...

  6. angular2 应用 不同的environment 进行 build/serve

    文件目录如下: 命令行使用:ng serve --e=dev/offline/prod build 不同,像上面那样写没用.必须后面再加--prod 如: ng build --e=offline - ...

  7. QT的QCombox

    https://stackoverflow.com/questions/29939990/qcombobox-style-for-choosed-item-in-drop-down-list

  8. eclipse通过maven进行打包并且对hdfs上的文件进行wordcount

    在eclipse中配置自己的maven仓库 1.安装maven(用于管理仓库,jar包的管理) -1.解压maven安装包 -2.把maven添加到环境变量/etc/profile -3.添加mave ...

  9. 如何控制table中td内的文本位置

    默认为左中效果    td中垂直用valign 取值为:top/middle/bottom/baseline,水平用align 取值为:left,center,right;

  10. 使用ArcSDE SQL操作怎么获得新对象的objectid、GUID

    arcgis9.3.1 现在大家很喜欢使用ArcSDE的SQL操作,这种方式在特殊的环境要求下显得比较方便,那么使用SQL操作最多的是读和写,而写最多的就是新建一个对象,那么翻译成SQL语言就是使用i ...