I've always thinking std::tuple
was something fancy but not really efficient.
But I learned that tuple are contiguous memory because of the rules of object layout. I know that tuples
are generate by inheritance and that's why we can't have dynamic tuples
. But at this point that's mean that tuples
are crazy good std::array
which can contains any type without any drawbacks.
Seems to me a little too powerful said like that.
So I wonder, how are tuples
inside the memory? There is really no other problems to tuples
?
Thanks to the answers which cleared my mind I got one big question
Is a "big" struct (can't really write a big one here) like
struct Foo {
int a;
float b;
double c;
};
as cache friendly than an array like
std::array<double, 3>
I need to often access to an element and change it. So I wonder if a computer will save a big struct in cache memory as easily than an array.
Anyway thanks