Boost logo

Boost :

Subject: Re: [boost] Proposal: Monotonic Containers
From: David Bergman (David.Bergman_at_[hidden])
Date: 2009-06-10 13:49:06


On Jun 10, 2009, at 4:54 AM, Christian Schladetsch wrote:

> Hi Artyom,
>
> You **must** return aligned pointers from allocators.
>
>
> boost::monotonic does not allocate.

I wonder what that 'allocator' of yours is for then? ;-)

Of course it allocates. And you fail to align the start address, which
makes certain use cases crash on certain platforms. On Intel, it
"just" gives the user a worse performance when misaligned. This is not
aligned (pun intended...) with your overall goal to give the developer
a high-performance tool. But do not take my word for it, I ran a test
with your container, the attached sample program and got around 33.3
picoseconds on average to perform an increment on an aligned long
compared to 35.6 picoseconds for a misaligned long, i.e., some 8%
difference. Actually, I got a bit more with other operations.

/David

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>

#include <boost/timer.hpp>

#include <boost/monotonic/vector.h>
#include <boost/monotonic/list.h>
#include <boost/monotonic/map.h>
#include <boost/monotonic/set.h>

template<typename C>
struct Foo {
   long ord;
   C c;
};

template<typename C>
void test_loop()
{
        boost::monotonic::inline_storage<100000> storage;
        boost::monotonic::vector<Foo<C> > vec(storage);
        const int LOOP_COUNT = 100000000;
        const int ELEM_COUNT = 1000;
        Foo<C> orig = { 'A', 65 };
        vec.assign(ELEM_COUNT, orig);
        boost::timer timer;
        for (int i = 0; i < LOOP_COUNT; ++i)
          ++vec[1 + i % (ELEM_COUNT - 2)].ord;
        double elapsed = timer.elapsed();
        std::cout << "Incrementing ord = " << 1000000000*elapsed/LOOP_COUNT
<< " ps per iteration" << std::endl;
}

int main(int argc, const char* argv[])
{
   test_loop<char>();
   test_loop<long>();
}


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