admin管理员组文章数量:1666599
几个相关class的定义位置:
system/core/libutils/RefBase.cpp 其中定义了class RefBase::weakref_impl
system/core$ vim include/utils/StrongPointer.h 其中定义了class sp
以以下代码运行为例:
链接:http://blog.csdn/mfbao01/article/details/6255655
class WPTest : public RefBase {
public:
WPTest(){
LOGD("WPTest constructor");
}
virtual ~WPTest() {
LOGD("WPTest destructor");
}
virtual void onFirstRef() {
LOGD("first weak ptr ref callback");
}
virtual void onLastStrongRef(const void* id) {
LOGD("last strong ptr ref callback");
}
virtual void onLastWeakRef(const void* id) {
LOGD("last weak ptr ref callback");
}
};
int main()
{
WPTest *T = new WPTest();
{
wp<WPTest> weakp(T);
{
LOGD("promote to strong ptr.../n");
sp<WPTest> strongp = weakp.promote();
LOGD("strong ptr's lifetime is just about to finish .../n");
}
LOGD("weak ptr's lifetime is just about to finish .../n");
}
LOGD("weak ptr is out of scope./n");
return 0;
}
第一步:调用wp构造方法
system/core/include/utils/RefBase.h
template<typename T> template<typename U>
wp<T>::wp(U* other)
: m_ptr(other)
{
if (other) m_refs = other->createWeak(this);
}
m_refs为weakref_type类型的指针
上一步调了实例对像W
版权声明:本文标题:Android中wp promote为sp流程 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1730074681a1221622.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论