4 ms·
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. Withou
by alain94040 10y ago
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.
- chubot 10y agoThe 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.
- MaulingMonkey 10y ago20.2.2 Pairs ¶ 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.