News for hackers. Stuff that matters.
Re:A cache miss is not a cache miss by alain94040 on Sunday May 01, 2016 @11:34AM (#11606552)
If you want to measure cache miss effects, you really should rewrite this code in C, so you know exactly what gets allocated in memory with what layout.

Without more details on data layout, you could be seeing the side-effect of aggressive pointer prefetching, which may only be possible with one layout but not another. Or there could be a fixed stride for some of the data allowing prefetchers to kick in. It's hard to tell and deserves some more experiments to isolate what is going on.

Re:A cache miss is not a cache miss by chubot on Sunday May 01, 2016 @11:54AM (#11606650)
The only type used in the demos is vector<pair<int,int>>. Vectors are guaranteed to be contiguous in memory. I'm pretty sure pairs are too, but that's easy to test:

    #include "stdio.h"
    #include <utility>
    printf("%zu\n", sizeof(std::pair<int, int>));

    8
So it's the obvious layout you would see in C with an array of struct { int x; int y }.

The cling interpreter is good for this kind of thing.

Re:A cache miss is not a cache miss by MaulingMonkey on Sunday May 01, 2016 @03:45PM (#11607576)
20.2.2 Pairs &para; 1 (ISO/IEC 14882:2003):

  The library provides a template for heterogeneous pairs of values. The library also provides a matching
  function template to simplify their construction.

      template <class T1, class T2>
      struct pair {
        typedef T1 first_type;
        typedef T2 second_type;
      
        T1 first;
        T2 second;
        pair();
        pair(const T1& x, const T2& y);
        template<class U, class V> pair(const pair<U, V> &p);
      };
      
      pair();
tl;dr: It looks like the 03 standard requires it to be equivalent to the plant C version in terms of layout, although that could involve padding between first and second if e.g. T1 = short and T2 = int, just like in the equivalent C code.