I'd like to pre-allocate a List<List<double>>
. I know I can pre-allocate 1-D Lists like this:
List<double> MyList = new List<double>(SomeSize);
Is it possible to do this for nested lists? In C++, I would do:
vector<vector<double>> MyList(OuterSize, vector<double>(InnerSize));
I cannot seem to find an efficient way to do this in C#, but I'm sure there's a way...
There is no such way, cause it's not a continuous piece of memory. You would have to program it yourself - iterating through the outer dimension.
A List is not really comparable to a C++ array. You allocate the memory for it, that means you avoid the growing of the List, but the List starts with Count=0, and you have to Add elements, you cannot access it by the indexer. And the initialization with the capacity is optional ! This is just increasing performance a little, if you know your final length in advance.
If you get along with a fixed-length array, you can allocate a multi-dimensional array like
at once.