I want to store 2D terrain information in memory (to be able to process it online) which can become very large. But because the terrain abstractions I'm using are sparsely populated this should not be a problem.
I took a look at the boost sparse matrix adapter classes:
and tried to play with their little demo program:
This should fill a matrix with all but zeros of size 3000x3000.
int main ()
using namespace boost::numeric::ublas;
mapped_matrix<char> m (3000, 3000);
for (unsigned i = 0; i < m.size1 (); ++ i)
for (unsigned j = 0; j < m.size2 (); ++ j)
m (i, j) = rand() + 1;
So it is not sparse and should take up 9 megabytes in memory.
If I instead use a vector<vector<char> > it does.
But if I run the test program I see top showing the VmSize going up to about 280 megabytes. Why is that?
Now even more weird: If I fill the matrix completely with zeros it should be very very sparse and should take up far below 9 megabytes in memory. But Top shows exactly the same as if I fill it with non-zero values.
The other sparse matrix adapters the boost library offers (I did not get the difference between them yet) behave about the same.
What did I miss?
Thank you in advance!