Boost logo

Boost :

Subject: Re: [boost] [root_ptr] Deterministic Javascript-like memory manager
From: Phil Bouchard (philippeb8_at_[hidden])
Date: 2017-07-09 02:39:08


On 07/08/2017 07:10 PM, Phil Bouchard via Boost wrote:
> Hello Boost / Qt,
>
> After some experience I have gained in Javascript over the last year, I
> decided to integrate root_ptr in a quest to replace their garbage
> collector.
>
> So I did and I already have an example. If we mimic the Javascript
> function scope in C++ then we'll have the following:
> https://github.com/philippeb8/root_ptr/blob/develop/example/javascript_example1.cpp
>
>
> The application was compiled with:
> g++ -fpermissive -DBOOST_DISABLE_THREADS -std=c++11 -I../include
> -I/usr/local/include -L/usr/local/lib -lboost_thread -lboost_system
> javascript_example1.cpp
>
> And it outputs:
> Scope 0: BEGIN
> Scope 1: BEGIN
> A::A(const boost::node_proxy&)
> A::A(const boost::node_proxy&)
> A::~A()
> Scope 1: END
> A::~A()
> Scope 0: END
>
> Which is exactly what we want. Note that I didn't stress tested it yet
> and in Brave New World we would be able to integrate it to other
> languages relatively easily given Javascript is a worse-case scenario.

I just made the example more complex and I am using a cycle:

struct A
{
     node_ptr<A> i;
     node_ptr<int> j;

     [...]
};

int main()
{
     cout << "Scope 0: BEGIN" << endl;
     {
         node_proxy x;
         node_ptr<A> a(x);

         cout << "Scope 1: BEGIN" << endl;
         {
             node_proxy x;
             node_ptr<A> b = make_node<A>(x, x, "b1");
             node_ptr<A> c = make_node<A>(x, x, "c1");

             a = b;

             b = make_node<A>(x, x, "b2");
             b->i = b;
         }
         cout << "Scope 1: END" << endl;
     }
     cout << "Scope 0: END" << endl;
}

And now I have:

Scope 0: BEGIN
Scope 1: BEGIN
A::A(const boost::node_proxy&, const char*): b1
A::A(const boost::node_proxy&, const char*): c1
A::A(const boost::node_proxy&, const char*): b2
A::~A(): c1
A::~A(): b2
Scope 1: END
A::~A(): b1
Scope 0: END

That is flawless... If anybody is willing to fool this memory manager
then please go ahead!

-Phil


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