Reputation: 353
I an using a data structure for storing sparse matrices as follow. Like if I am having a matrix as follows
I am using a vector of pairs to store the data. So is it better to store these value in a single vector like this:-
or will it be better to store them like this:-
I am using a seperate vector to store data about starting and end indexes for each row.
Which of the two methods will use less memory?????
Upvotes: 0
Views: 179
Reputation: 2908
Because a vector allocates a single block of contiguous memory (unlike a list), a single vector would use less memory by consolidating the heap overhead. I assume the client interface is the same regardless (overloading operator[], for example), so your question is just about memory efficency.
Upvotes: 1