Boost logo

Boost :

From: ÒÝÁØ Ñî (yyl_20050115_at_[hidden])
Date: 2020-08-02 00:20:13


Hi,

Please allow me to say something about the background.

About 15 years ago, first time, I tried to write a gc framework for C++. It worked, but just too slow to use.

Currently, I¡¯m studying source code of GO language. The book I bought has a chapter talking about how GO¡¯s GC works.
And this remind me to think GC again. In C#, Java or GO, they all use GCs, and that¡¯s something I really
like: so that I can focus on ideas, not just low level jobs (the good for this is more efficient).

A week ago, a friend called me to ask if I can code COM classes to assist the Drag/Drop or Copy/Paste
between his application and the Explorer (desktop). I told him I can and then did the work.
COM objects uses reference counting method just like intrusive_ptr which explained by its name.
With COM IUnknown, you should do AddRef and Release manually, on the other hand shared_ptr manages pointers automatically,
Which is much better choice. However, shared_ptr requires weak_ptr, which is not so easy-going like things
In C# or Java (mostly because of the circular reference problem).

Other work of mine is about compilers, especially the front end, the parser etc. When you generate AST from
parsing stage or solve types¡¯ relationship, you would find it very easy to make circular reference. So this requirement
for me is not just imaginary but very practical.

These things came together, inspired me to think of some solution which can solve problems on both sides:
After carefully studying why the refence count does not decrease to zero when circular refencing, I did a lot
experiments to solve that. The almost last working one was the IDispose solution.
However, ugly as I see ¨C acceptable for C# or Java
in which you have to call Dispose(bool disposing) manually in finalizer, but not C++.

After a few adjustment, I got this version.

That¡¯s the story.

I don¡¯t want to argue about the multiple calling of the destructors any more.
Because for me, with certain protections, it just works as expected.
And I can not find a reason that the language or runtime do anything between deters¡¯ calling
And free(ptr)¡¯s calling. So the data has to be safe as never touched, and then the protection
must work as expected. Meaning, everything is just fine and not ugly, only maybe not according to the
C++ standard. For others, the pattern of IDisposable is always there at your own choice, and you don¡¯t
need to follow my ¡°bad design example¡±.

And I hope you can see this: with some kind of changing-point-of-view, Reference Counting can work perfectly,
even with circular reference. Therefore if you use this method in C++, you get the all benefit from it,
and if you use it with GC, STOP-THE-WORLD would be not necessary any more.

This is the innovation I talk about.

Again, fighting against C++¡¯s standard is never my purpose, making life easier with a new algorithm is.


Best Regards,
Yilin



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk