经过无数次思考我决定放弃使用一般的 GC 算法,直接用引用计数法。
例子程序:
#include<xnet/core>
#define gcnew(T,...) ((::geelaw::xNET::Core::gcref< T >)new T ( __VA_ARGS__ ))
using namespace geelaw::xNET::Core;
#include<cstdio>
struct SampleObject : virtual Object
{
SampleObject()
{
std::puts("SampleObject::SampleObject()");
}
~SampleObject()
{
std::puts("SampleObject::~SampleObject()");
}
};
int main()
{
gcref<Object> o = new SampleObject();
delete new SampleObject();
gcnew(SampleObject);
}
预期输出:
SampleObject::SampleObject()
SampleObject::SampleObject()
SampleObject::~SampleObject()
SampleObject::SampleObject()
SampleObject::~SampleObject()
SampleObject::~SampleObject()
例子程序:
#include<xnet/core>
#define gcnew(T,...) ((::geelaw::xNET::Core::gcref< T >)new T ( __VA_ARGS__ ))
using namespace geelaw::xNET::Core;
#include<cstdio>
struct SampleObject : virtual Object
{
SampleObject()
{
std::puts("SampleObject::SampleObject()");
}
~SampleObject()
{
std::puts("SampleObject::~SampleObject()");
}
};
int main()
{
gcref<Object> o = new SampleObject();
delete new SampleObject();
gcnew(SampleObject);
}
预期输出:
SampleObject::SampleObject()
SampleObject::SampleObject()
SampleObject::~SampleObject()
SampleObject::SampleObject()
SampleObject::~SampleObject()
SampleObject::~SampleObject()