Reputation: 145
I'm designing an upgrade to an older C++ assembly and want to (re-)do this right.
The situation is, I've got an object that is basically a "database" (it's various bits of data taken over lots of time-steps). The issue is I don't know what each "column" will hold until run-time.
There are about 30 column name possibilities. Speed is a major concern.
The old structure uses an array to store the column names (they're enums), and an array of arrays to hold the data. You'd find the column name in the header array, then use that column index to find the right bit of data in the current data "row". It's a perfectly viable idea, but it seems a bit...out of date.
I'd include each possible column as a property in a "row" object, it seems this would massively inflate the memory usage and creation time (which isn't acceptable).
Is there a standard structure for this kind of thing?
Upvotes: 1
Views: 752
Reputation: 81459
Yes, take a look at the DataSet class in the System.Data namespace.
The DataSet is the top-level container for DataTables, Relations and other "database-like" objects. In the DataTables you can define your columns and populate your rows as you wish. You can also easily persist the whole thing via serialization.
Upvotes: 2