12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #ifndef AFUN_GC_HPP
- #define AFUN_GC_HPP
- #include "tool.hpp"
- #include "aFunCoreExport.h"
- #include "queue"
- namespace aFuncore {
- typedef unsigned GcCount;
- class GcObjectBase {
- bool not_clear; // 不清除
- GcCount reference; // 引用计数
- bool reachable; // 可达标记 [同时标识已迭代]
- public:
- GcObjectBase() : not_clear{false}, reference{0}, reachable{false} {}
- };
- template <class T>
- class GcObject : public GcObjectBase {
- T *prev;
- T *next;
- public:
- GcObject();
- virtual ~GcObject()=default;
- void addObject(T *&chain);
- void delObject(T *&chain);
- static void destruct(T *&chain);
- };
- class GcList {
- std::queue<GcObjectBase *> queue;
- public :
- AFUN_CORE_EXPORT size_t add(GcObjectBase *obj);
- AFUN_CORE_EXPORT GcObjectBase *pop();
- [[nodiscard]] size_t getSize() const {return queue.size();}
- [[nodiscard]] size_t isEmpty() const {return queue.empty();}
- };
- };
- #endif //AFUN_GC_HPP
|