Boost logo

Boost :

Subject: Re: [boost] [Root Pointer] Benchmark
From: Phil Bouchard (philippeb8_at_[hidden])
Date: 2016-03-15 19:02:05


On 03/14/2016 08:57 PM, Glen Fernandes wrote:
> On Mon, Mar 14, 2016 at 8:43 PM, Phil Bouchard wrote:
>> No I just scribbled something quickly but I need to clean up node_base.hpp
>> and make nodealloc<> generic.
>>
>
> Understood. Given that: I've updated the example code to be slightly
> less trivial:
>
> https://github.com/philippeb8/root_ptr/issues/1
>
> After you have updated/cleaned up the code as you've specified, the
> only changes involved should be:
>
> 1. shared_ptr<U> becomes root_ptr<U>
> 2. allocate_shared<U>(Allocator<U>(x, y), p, q) becomes <something>
>
> That <something> should ideally be a single expression where you can
> specify both:
>
> a. Allocator<U> instance
> b. U constructor arguments

Ok I fixed it and the code will look like the following:

int main()
{
     int n1 = 0, m1 = 0;
     int n2 = 0, m2 = 0;
     {
         typedef boost::node<U, Allocator<U> > node;
         typedef typename node::allocator_type allocator_type;

         boost::root_ptr<U> p1, p2, p3;

         allocator_type a1(n1, m1);
         p1 = new (a1) node(a1, 1, 'a');

         allocator_type a2(n2, m2);
         p2 = new (a2) node(a2, 2, 'b');

         allocator_type a3(n2, m2);
         p3 = new (a3) node(a3, 3, 'c');

         if (n1 != 1 || m1 != 1 || n2 != 2 || m2 != 2) {
             throw 3;
         }
     }
     if (n1 != 0 || m1 != 0 || n2 != 0 || m2 != 0) {
         throw 4;
     }
}

Or:
https://github.com/philippeb8/root_ptr/blob/master/example/allocator.cpp

But I found a problem with pool_allocator::construct() because it is not
a template function. Thus this prevents other examples to compile.

Thanks,
-Phil


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