
On Jun 10, 2009, at 1:49 PM, David Bergman wrote:
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.
In fact, the attached version is a very lenient one, since it does give proper alignment for a lot of iterations... I used prime number distributions in other samples. Nevertheless, this sample produced between 8% and 10% difference between the two cases. I can provide you with more information about the performance hit of using misaligned stuff if you want. /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>(); }
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost