According to the boost:
"for example expressing a 2-dimensional array of double elements using the type std::vector<std::vector<double>>, but the resulting interface is unwieldy and the memory overhead can be quite high"
I thought that the memory of multi_array should be lower than
vector, but the fact is--the memory of multi_array are much more
larger than vector?
Do I do something wrong? I should not use sizeof to measure
the memory of multi_array?
sizeof( std::vector<anything> ) is always 12 on my machine, regardless of how many elements are in it.
Why? Because std::vector<> only contains three pointers. The actually underlying array is dynamically
allocated, and the pointers are pointing to various places within it.
The same holds for boost::multi_array<>, I'm sure.
Maybe it is. However when you use vector< vector<> > for 100x100 array, the size is sizeof(vector)+100*sizeof(vector). When you use multi_array, it remains 48.
I thought the sizeof vector< vector<> > for 100x100 array
should be sizeof(vector) + 100*100*sizeof(your type)?
But I don't know the details of multi_array
still surfing on website
Anyway, thanks a lot
@stereoMatching, no. I was only talking about the overhead.
100x100 vector< vector< Type> > takes sizeof(vector) + 100*sizeof(vector) + 100*100*sizeof(Type) bytes
100x100 multi_array takes sizeof(multi_array) + 100*100*sizeof(Type)
that is because in vector<vector<>> you need to have 100 vector objects (one for each row)