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

网站赚钱思路网站seo与网站没关

网站赚钱思路,网站seo与网站没关,南昌网站建设一般多少钱一年,微动网站建设前言 最近解决稳定性问题#xff0c;遇到sp问题#xff0c;本文就简单梳理RefBase和sp、wp下。 RefBase RefBase是Android中所有对象的始祖#xff0c;类似于MFC中的CObject及Java中的Object对象。在Android中#xff0c;RefBase结合sp和wp#xff0c;实现了一套通过引…前言 最近解决稳定性问题遇到sp问题本文就简单梳理RefBase和sp、wp下。 RefBase RefBase是Android中所有对象的始祖类似于MFC中的CObject及Java中的Object对象。在Android中RefBase结合sp和wp实现了一套通过引用计数的方法来控制对象生命周期的机制。 sp的意思应该是strong pointer而wp则是weak pointer的意思。Android推出这一套机制可能是模仿Java因为Java世界中有所谓weak reference之类的东西。sp和wp的目的就是为了帮助健忘的程序员回收new出来的内存。 // 类A继承自RefBase class A : RefBase { }int main{A *pa new A();{spA spA(pa);wpA wpA(pa);// 大括号结束后析构wp和sp}return 0; }RefBase system/core/include/utils/RefBase.h system/core/libutils/RefBase.cpp class RefBase { public:void incStrong(const void* id) const;void decStrong(const void* id) const;void forceIncStrong(const void* id) const;int32_t getStrongCount() const;class weakref_type{public:RefBase* refBase() const;void incWeak(const void* id);void decWeak(const void* id);bool attemptIncStrong(const void* id);};weakref_type* createWeak(const void* id) const;weakref_type* getWeakRefs() const;protected:RefBase();virtual ~RefBase();//! Flags for extendObjectLifetime()enum {OBJECT_LIFETIME_STRONG 0x0000,OBJECT_LIFETIME_WEAK 0x0001,OBJECT_LIFETIME_MASK 0x0001};void extendObjectLifetime(int32_t mode);//! Flags for onIncStrongAttempted()enum {FIRST_INC_STRONG 0x0001};virtual void onFirstRef();virtual void onLastStrongRef(const void* id);virtual bool onIncStrongAttempted(uint32_t flags, const void* id);virtual void onLastWeakRef(const void* id);private:friend class weakref_type;class weakref_impl;RefBase(const RefBase o);RefBaseoperator(const RefBase o);weakref_impl* const mRefs; };创建RefBase时同时创建影子对象weakref_impl名为mRefs。 mRefs是引用计数管理的关键类它是从RefBase的内部类weakref_type中派生出来的(继承)。 class RefBase::weakref_impl : public RefBase::weakref_type { public:std::atomicint32_t mStrong;std::atomicint32_t mWeak;RefBase* const mBase;std::atomicint32_t mFlags;weakref_impl(RefBase* base): mStrong(INITIAL_STRONG_VALUE), mWeak(0), mBase(base) // 实际对象, mFlags(0){}... }// 构造函数会同时创建其内部类(影子对象)weakref_impl RefBase::RefBase(): mRefs(new weakref_impl(this)) { }// 强引用1 void RefBase::incStrong(const void* id) const {weakref_impl* const refs mRefs;refs-incWeak(id);refs-addStrongRef(id);const int32_t c refs-mStrong.fetch_add(1, std::memory_order_relaxed);ALOG_ASSERT(c 0, incStrong() called on %p after last strong ref, refs); #if PRINT_REFSALOGD(incStrong of %p from %p: cnt%d\n, this, id, c); #endifif (c ! INITIAL_STRONG_VALUE) {return;}int32_t old refs-mStrong.fetch_sub(INITIAL_STRONG_VALUE,std::memory_order_relaxed);// A decStrong() must still happen after us.ALOG_ASSERT(old INITIAL_STRONG_VALUE, 0x%x too small, old);refs-mBase-onFirstRef(); }// 强引用-1 void RefBase::decStrong(const void* id) const {weakref_impl* const refs mRefs;refs-removeStrongRef(id);const int32_t c refs-mStrong.fetch_sub(1, std::memory_order_release); #if PRINT_REFSALOGD(decStrong of %p from %p: cnt%d\n, this, id, c); #endifALOG_ASSERT(c 1, decStrong() called on %p too many times, refs);if (c 1) {std::atomic_thread_fence(std::memory_order_acquire);refs-mBase-onLastStrongRef(id);int32_t flags refs-mFlags.load(std::memory_order_relaxed);if ((flagsOBJECT_LIFETIME_MASK) OBJECT_LIFETIME_STRONG) {delete this;// Since mStrong had been incremented, the destructor did not// delete refs.}}// Note that even with only strong reference operations, the thread// deallocating this may not be the same as the thread deallocating refs.// Thats OK: all accesses to this happen before its deletion here,// and all accesses to refs happen before its deletion in the final decWeak.// The destructor can safely access mRefs because either its deleting// mRefs itself, or its running entirely before the final mWeak decrement.refs-decWeak(id); }sp frameworks/rs/cpp/util/StrongPointer.h template typename T class sp { public:inline sp() : m_ptr(0) { }sp(T* other);sp(const spT other);templatetypename U sp(U* other);templatetypename U sp(const spU other);~sp();// Assignmentsp operator (T* other);sp operator (const spT other);templatetypename U sp operator (const spU other);templatetypename U sp operator (U* other);//! Special optimization for use by ProcessState (and nobody else).void force_set(T* other);// Resetvoid clear();// Accessorsinline T operator* () const { return *m_ptr; }inline T* operator- () const { return m_ptr; }inline T* get() const { return m_ptr; }// OperatorsCOMPARE()COMPARE(!)COMPARE()COMPARE()COMPARE()COMPARE()private:templatetypename Y friend class sp;templatetypename Y friend class wp;void set_pointer(T* ptr);T* m_ptr; };templatetypename T spT::sp(T* other) : m_ptr(other){if (other) other-incStrong(this);}templatetypename T spT::~sp() {if (m_ptr) m_ptr-decStrong(this); }wp template typename T class wp { public:typedef typename RefBase::weakref_type weakref_type;inline wp() : m_ptr(0) { }wp(T* other);wp(const wpT other);wp(const spT other);templatetypename U wp(U* other);templatetypename U wp(const spU other);templatetypename U wp(const wpU other);~wp();// Assignmentwp operator (T* other);wp operator (const wpT other);wp operator (const spT other);templatetypename U wp operator (U* other);templatetypename U wp operator (const wpU other);templatetypename U wp operator (const spU other);void set_object_and_refs(T* other, weakref_type* refs);// promotion to spspT promote() const;// Resetvoid clear();// Accessorsinline weakref_type* get_refs() const { return m_refs; }inline T* unsafe_get() const { return m_ptr; }// OperatorsCOMPARE_WEAK()COMPARE_WEAK(!)COMPARE_WEAK()COMPARE_WEAK()COMPARE_WEAK()COMPARE_WEAK()inline bool operator (const wpT o) const {return (m_ptr o.m_ptr) (m_refs o.m_refs);}templatetypename Uinline bool operator (const wpU o) const {return m_ptr o.m_ptr;}inline bool operator (const wpT o) const {return (m_ptr o.m_ptr) ? (m_refs o.m_refs) : (m_ptr o.m_ptr);}templatetypename Uinline bool operator (const wpU o) const {return (m_ptr o.m_ptr) ? (m_refs o.m_refs) : (m_ptr o.m_ptr);}inline bool operator (const wpT o) const {return (m_ptr o.m_ptr) ? (m_refs o.m_refs) : (m_ptr o.m_ptr);}templatetypename Uinline bool operator (const wpU o) const {return (m_ptr o.m_ptr) ? (m_refs o.m_refs) : (m_ptr o.m_ptr);}inline bool operator ! (const wpT o) const { return m_refs ! o.m_refs; }templatetypename U inline bool operator ! (const wpU o) const { return !operator (o); }inline bool operator (const wpT o) const { return !operator (o); }templatetypename U inline bool operator (const wpU o) const { return !operator (o); }inline bool operator (const wpT o) const { return !operator (o); }templatetypename U inline bool operator (const wpU o) const { return !operator (o); }private:templatetypename Y friend class sp;templatetypename Y friend class wp;T* m_ptr;weakref_type* m_refs; };templatetypename T wpT::wp(T* other): m_ptr(other) {if (other) m_refs other-createWeak(this); }templatetypename T spT wpT::promote() const {spT result;if (m_ptr m_refs-attemptIncStrong(result)) {result.set_pointer(m_ptr);}return result; }理解Refbase强弱引用 深入理解Android(卷l)
http://www.pierceye.com/news/32470/

相关文章:

  • 网站设计排版布局哪里的网络推广培训好
  • 东营做网站seowordpress技术网主题
  • 建站程序下载东莞市网站建设制作设计平台
  • 自己做一个网站难么ui设计师做网站
  • 网站建设需要注意哪些事项网站 制作价格表
  • 郑州模板建站多少钱wordpress健康资讯模板
  • 做啥网站流量高上海网站推广排名公司
  • 网站中图片加水印关于网站建设的申请书
  • discuz做的网站上传到网站空间的文件重庆建设网站公司哪家好
  • 做电影网站还能赚钱wordpress图集插件
  • 东莞网站建设员wordpress会员插件大全
  • 下载了网站建设aspwordpress国产课程主题
  • 在线做logo印章网站制图软件免费
  • 做公司网站找谁作一手房用什么做网站
  • 南宁品牌网站建设网站几个模板最好
  • 手机网站开发免费视频教程网站建设优化哪家公司好
  • 怎么开网站做站长长春网站制作外包
  • 环保网站模板代码格尔木哪里有做网站的
  • 婚纱摄影网站的设计与实现论文wap网站后台模板
  • 南昌网站建设制作商食品包装设计理念
  • 购物网站的设计思路网页美工设计书本
  • 网站模块制作WordPress按评论时间排序
  • 网站除了域名还要什么做网站用什么后缀好
  • 站长工具劲爆中国商机创业网
  • 网站前面的小图标怎么做佛山厂家关键词网络推广
  • 制作网站要多久毕业设计代做网站机械
  • 苏州免费网站建设莆田网站建设
  • 网站推广昔年下拉网站建设方案书生鲜
  • 哈尔滨自助建站模板广州海珠区发布
  • 万网icp网站备案专题做网店好还是自己建网站好