4 ms·
> proposes a vector of vectors to make a 2D matrix what would be the right way to do this?
by Nimitz14 11y ago
> proposes a vector of vectors to make a 2D matrix
what would be the right way to do this?
- Stasis5001 11y ago2D arrays that are laid out as a linear array of mn elements are faster to iterate through. That's what happens when you declare e.g. int a[5][4], you get the same layout as int a[20]. A vector of vectors is fairly sprawling in memory, and generally matrices don't get resized so you want this compact form because it's quicker to loop through (either way is O(mn), but one has a way better coefficient).