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

精美的php个人网站源码河南网站备案代理

精美的php个人网站源码,河南网站备案代理,wordpress微信免签支付接口,网络舆情中心前言 最近解决稳定性问题#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.huolong8.cn/news/216815/

相关文章:

  • 建设网站申请书重庆荣昌网站建设公司
  • 正常做网站多少钱wordpress 留言表单
  • 视频网站怎样做wordpress投稿者权限
  • 个人电脑做网站服务器网站网站建设术语 英文
  • 怎么样自己创建网站泰州网站建设
  • 大连做网站制作个人网站开发技术
  • 泰兴网站建设价格网站营销管理培训班
  • 网站开发遇到的问题及解决方法古风自己做头像的网站
  • 那个网站做代买江苏省工程建设招标网站
  • 深圳网站制作工作室设计师案例网站
  • wp网站开发如何搭建手机网站源码
  • 怎么在百度上建网站自媒体视频剪辑培训班
  • 微信小程序网站模板在线法律咨询免费
  • 新八建设集团有限公司网站怎么建立淘宝客网站
  • 有哪些做废品的网站asp.net mvc网站发布教程
  • 网站建设whjzyh常宁城乡建设局网站查询
  • asp.net 网站开发视频教程巢湖网站开发
  • 网站建设费用兴田德润团队制作php网站
  • 做网站空间500m多少钱深圳市福田区
  • 徐州网站设计制作建设深圳网站建设商家
  • flash制作网站top建筑工程网上教育平台
  • 网站木马诊断网站建设有哪些环节
  • 做企业网站需要提供什么百度 手机网站 友好性
  • 上海制作网站的网站石家庄官网
  • 做网站二级域名随便用吗wordpress正在执行例行维护
  • 高端建设网站公司舆情分析招聘
  • 县市区科普网站建设建设360导航网站的目的是什么意思
  • 深圳官方网站建设建设购物网站要求
  • 什么程序做网站蓝色网站模板
  • 潍坊 优化型网站建设最新cms