I know that the DataTable is using boxing/unboxing when we are inserting/getting the data. If we have a really big amount of data containing only int's for example, isn't it faster to use some sort of generic DataTable , let's say MyDataTable<int>, which will result in avoiding boxing/unboxing overhead?
Strings are reference-types, so there is no boxing overhead: they are never boxed. DataTable does have plenty of overheads though - that is the cost of being able to represent arbitrary column models along with constraints, change-tracking, etc. For optimum performance, a POCO model is hard to beat. For example:
public class Customer {
public int Id { get; set; }
public string Name { get; set; }
// ...
}
There are plenty of ORMs and micro-ORMs that make working with this type of model.
Note, however, that in DataTable, the values are stored in correctly-typed arrays. Ints are stored in an int[] - which is does by storing data in columns rather than rows. Boxing only happens when getting data into/out-of the DataTable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With