惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
Jina AI
Jina AI
博客园_首页
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
L
Lohrmann on Cybersecurity
Forbes - Security
Forbes - Security
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
N
News | PayPal Newsroom
S
Security Archives - TechRepublic
量子位
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
C
Cisco Blogs
The Cloudflare Blog
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
Scott Helme
Scott Helme
S
Securelist
Security Latest
Security Latest
爱范儿
爱范儿
TaoSecurity Blog
TaoSecurity Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
I
Intezer
L
LINUX DO - 最新话题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
美团技术团队
Know Your Adversary
Know Your Adversary
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
PCI Perspectives
PCI Perspectives
月光博客
月光博客
T
Tailwind CSS Blog
Cloudbric
Cloudbric
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
K
Kaspersky official blog
D
DataBreaches.Net
博客园 - 【当耐特】
有赞技术团队
有赞技术团队

博客园 - Think

[开源]jquery.ellipsis根据宽度(不是字数)进行内容截断,支持多行内容 jquery代码链实现延时执行代码【补:几点注意】 根据用户选的背景色,自动匹配一个前景色 jquery代码链实现延时执行代码的较优雅办法 C++11智能指针处理Array对象 低端用户反文化----这个问题真这么简单? 放暑假了 jQuery 1.7.2 animate功能跨浏览器Bug修补 AsyncEnumerator对EAP的支持 大数据块(BLOBs)与流(Stream)操作性能规范 SQL Antipatterns内容介绍 Chromium Embedded Framework中文文档 (如何链接不同的运行时) Chromium Embedded Framework中文文档 (SVN属性) Chromium Embedded Framework中文文档 (升级到最新的Chrome) Chromium Embedded Framework中文文档之(基本使用) Chromium Embedded Framework 中文文档(简介) 操盘之王 摘要 市场营销经典《引爆点》简摘 强制iphone界面马上旋转
Chromium Embedded Framework中文文档 (使用C API)
Think · 2011-10-06 · via 博客园 - Think

简介

CEF的C API是由libcef DLL暴露的基于C的接口,cef_capi.h 头文件中定义的接口是由CEF translator tool自动生成的C++ API镜像。

引用计数

理解引用计数可能是使用CEF C API最困难的部分了,CEF使用引用计数概念类似于COM的概念,这里有一些基本的规则可以帮助你减少使用引用计数时的困难。

1. 当将一个结构传给它自己的成员函数时,不要进行引用计数的加、减操作:

struct->call_func(struct,...); // no reference counting change on 'struct'

2. 在将结构作为参数传给其它结构前,增加引用计数:

// Should have already added a reference to 'some_other_struct' struct->call_func(...,some_other_struct,...);

3. 在你使用完从别处以参数传过来的结构后,减少它的引用计数:

void my_func(...,some_other_struct,...) { // remove a reference from 'some_other_struct' after you're done using it }

4. 在传入一个处理程序前,增加它的引用,比如,cef_create_browser(),当API不再需要使用某一处理程序时,会移除它的引用。

5. 使用原子的引用计数实现,因为add_ref和release可能会跨线程调用,WinAPI InterlockedIncrement() 和 InterlockedDecrement() 函数可用于此目的。

6. 如果引用计算变成0,处理程序应该在已赋值给结构的releae()回调函数中删除自己:

 // custom data structure that extends cef_handler_t

typedef struct _my_handler_t {
  cef_handler_t handler; // cef_handler_t member comes first
  // custom members here, including the reference count variable
} my_handler_t;

// allocate the custom data structure (already initialized to zero)
my_handler_t* my_handler = (my_handler_t*)calloc(1, sizeof(my_handler_t));
// set the size member of cef_base_t appropriately
my_handler->handler.base.size = sizeof(cef_handler_t);
// assign the release callback function (and the other callback functions)
my_handler->handler.base = my_release;
...

// release callback function implementation for my_handler_t
int CEF_CALLBACK my_release(struct _cef_base_t* base) {
  // this cast works because cef_base_t is the first member of
  // cef_handler_t and cef_handler_t is the first member of my_handler_t
  my_handler_t* my_handler = (my_handler_t*)base;
 
  // decrement the reference count (stored as a custom member of my_handler_t)
  // free the my_handler_t structure when the reference count reaches zero
  if(reference_count_is_zero)
    free(my_handler);
}

7. 清除代码添加给结构的所有附加的引用(比如,在处理程序实现中保持cef_broswer_t指针的引用),最终的释放引用的机会是cef_handler_t::handle_before_window_closed()。

8. 如果没有任何的crash产生,在shutdown时也会命中DebugObjCt断言,那么就说明你正确的处理了引用计数。