Value types (structs) are intended to be used where a lightweight (few
members, little instance data, generally do not persist for long) type is
required.  It's also not well designed for huge collections of data.
Value types are allocated from the stack rather than from the heap.  So,
for large collections of large value types you need to consider the stack
ramifications.

Also, when value types are used where object is expected, boxing occurs.
If you're using a collection class that is really just a collection of
object-based references, each reference will be a copy of the original
value type.  The implication of this (other than performance) is if you
modify what's in the collection you may only be modifying a copy and the
next time you get that value out of the collection your modifications may
be ignored.  Calling any of the object class's members (Equals(),
GetHasCode(), GetType(), ToString()) with your value type will result in
boxing as well--usually this just has performance ramifications.

On a more philosophical note, structs must have a public default
constructor.  If your data type's invariant must be initialized from
another set of data, then struct may not be the best choice.

On Thu, 12 Jan 2006 10:13:30 +0000, Girish Jain <[EMAIL PROTECTED]>
wrote:

>Hi All,
>
>I have to read a fixed length file which has about 52000 entries and store
>these entries into a database table. I have created a new type and it has
>properties which are mapped to the columns in the file. I have created a
>collection class to store all the instances. The collection class inherits
>from the CollectionBase class. Therefore, internally I am adding all the
>instances to the ArrayList.
>
>I am just thinking about whether I should be creating the new type as a
>struct or a class i.e. value type or reference type. I am asking this just
>to check on the performance as it has very large number of entries in it.
>The type has some 19 fields out of which 2 are DateTime, 2 integers and
one
>char, and rest are string values.

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to