You've got a lot of pointers here, and each pointer has allocation overhead. The pointers refer to small objects, and so the overhead is significant.
On top of that, dynamically allocated objects necessarily have more overhead than fixed size objects. That's because fixed size objects do not need to store matrix dimensions.
Here are the sources of your pointer overhead:
Eigen::VectorXd
uses dynamically allocated storage. That means a pointer.- You store the objects in
std::vector<SSCCE_struct*>
. And that's another pointer, with overhead.
The most efficient way to store these objects is to remove the indirection. You can do that by switching to:
Matrix<double, 5, 1>
. This is a fixed size object and so has no indirection. What's more, as explained above, it does not need to store the matrix dimensions at runtime because they are known at compile time. For such a small object that is significant.- Store the objects in
std::vector<SSCCE_struct>
. Again, you lose one level of indirection.
With these changes, the memory usage of your program, when compiled with release settings, drops to 383MB on my machine. That's much more in line with your expectations.
The big difference seems to be between Eigen::VectorXd
and the fixed size object. If I use Eigen::VectorXd
and std::vector<SSCCE_struct>
then the memory usage jumps to 918MB. When I then go to std::vector<SSCCE_struct*>
it makes a further jump to 1185MB.
These measurements will be highly dependent on the compiler. I've used VS2013 compiling 32 bit code.