Hi,

Thanks to all of you for your valuable inputs. I did some performance
testing and the results are surprising.

The new type holds all the data to be inserted in to the database (in the
local class variables) and has a property namely SQL which returns the
INSERT SQL statement. By iterating over the items of the collection using
for each loop I am inserting the records into the database. For reading the
lines from the file I am using regular expressions.

When I made the new type as value type and with some 22,000 records it took
approx 25 seconds less time. With several tests, this time ranged between 23
to 25 seconds. Therefore, with value type the performance is really good.

Now, if somebody can throw some light on this AND highlight the criterias
(not generic ones) that I should always be considering for value types or
reference types with regards to **memory** usage, because every time I dont
want to decide the type after doing this performance testing.


Regards,
Girish Jain

From: Peter Ritchie <[EMAIL PROTECTED]>
Reply-To: "Discussion of advanced .NET topics."
<ADVANCED-DOTNET@DISCUSS.DEVELOP.COM>
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [ADVANCED-DOTNET] New Type decision Criterias
Date: Thu, 12 Jan 2006 16:34:45 -0500

Sorry, I should have been more clear.  When I said "collections" I didn't
mean arrays, I meant classes derived from classes within
System.Collections.


Also, I was under the impression that C# simply mapped array definitions
to the Array class.  So:

S[] array = new S[10000];

is directly allocating a reference type.  I was also under the impression
that the Array type managed its own memory (e.g. in the above example it
isn't allocating 10000 individual value types)

I assume the value types in this example are allocated from the stack:
 ArrayList al = new ArrayList();
 for(int i = 0; i < 10000; i++)
 {
  al.Add(i);
 }

If you're processing lines of a file you're more likely to use a
Collections based class than a language-supplied array.

http://www.peterRitchie.com/

On Thu, 12 Jan 2006 22:10:07 +0100, Fabian Schmied <[EMAIL PROTECTED]>
wrote:

>> 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.
>
>Value types are only allocated on the stack in some cases
>(http://www.pobox.com/~skeet/csharp/memory.html).
>
>"Collections of value types" are indeed typically not allocated on the
>stack, so you don't need to consider the stack ramifications there.
>(Unless you are talking about collections in the sense of a large
>number of local variable declarations, but I don't think you will
>easily run into stack problems with local variable declarations.)
>
>In particular, in code similar to the following, the array will not be
>allocated on the stack, even if array is a local variable:
>
>int[] array = new int[10000];
>
>The same applies with newly defined value types:
>
>struct S {
>}
>
>S[] array = new S[10000];
>
>IIRC, this can be much more memory efficient than the equivalent:
>
>class C {
>}
>
>C[] array = new C[10000];
>for (int i = 0; i < 10000; ++i) {
>  array[i] = new C();
>}
>
>The struct way is more runtime efficient, too, because value types can
>be initialized without their constructors being run [1].
>
>Fabian
>
>[1] The public default constructor of value types can be simulated by
>filling a block of memory with zeroes.

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

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

===================================
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