Search code examples
memorysparse-matrixeigen

Eigen empty sparse matrix memory usage


I'm trying to understand the memory usage of my program which is using EIGEN, and there's a part related to EIGEN that I'm not understanding.

I'm creating a SparseMatrix<short,RowMajor>(2,3), empty, and the cost of this is 12 bytes. Inner and Outer index are int.

I was expecting 8 bytes and I don't understand why I'm 1 integer lower than the effective cost. Here is my calculation :

Cost of non zeroes values = 0 bytes
Cost of inner index = 0 bytes
Cost of outer index = 2 rows * 4 bytes = 8 bytes
Total cost = 8 bytes

I guess my mistake is on the inner index cost, but I don't understand why? The whole matrix is empty so the inner array should be empty too?

Thanks in advance.


Solution

  • Look there, the outer index buffers has one more entry to store the end position of the last row.