Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Usage of Array in C#.NET

Reply
 
Old 08-04-2009   #1 (permalink)
Curious


 
 

Usage of Array in C#.NET

I have a colleague who used to program in S-PLUS. My impression about
S-PLUS is that it's based on matrix calculations and consumes a lot of
memory. It takes a long time to run a small program in S-PLUS.

Now he wants to learn C# in order to speed things up. He simply uses
Array in C#.NET (to resemble matrix in S-PLUS). He refers to
everything in the Array by indexes, i.e., integer numbers. It seems
fairly abstract.

I asked him to use objects and ArrayList. He is not used to the
concept of object-oriented programming. So he sticks to the Array with
those indexes. Each time when he asks me to help debug, it's a
headache because I have to remember the indexes that reference to
different things. All meaningless numbers pointed to by indexes.

A question for you folks: Is it a good idea to use Array? Wouldn't it
be better to use ArrayList instead?


My System SpecsSystem Spec
Old 08-04-2009   #2 (permalink)
Adam Benson


 
 

Re: Usage of Array in C#.NET

I must say, I know nothing about S-Plus, and you don't really say what he's
storing in these arrays.
If he's just storing ints then why not use int[]? or at least List<int>?
Quote:

> He refers to everything in the Array by indexes, i.e., integer numbers.
I must be missing something here - how else would you index into an array?
Why do you think using an int to index into the array is wrong?

Cheers,

Adam.


"Curious" <fir5tsight@xxxxxx> wrote in message
news:a5676adb-3ea9-489a-8e43-ceb58407975e@xxxxxx
Quote:

>I have a colleague who used to program in S-PLUS. My impression about
> S-PLUS is that it's based on matrix calculations and consumes a lot of
> memory. It takes a long time to run a small program in S-PLUS.
>
> Now he wants to learn C# in order to speed things up. He simply uses
> Array in C#.NET (to resemble matrix in S-PLUS). He refers to
> everything in the Array by indexes, i.e., integer numbers. It seems
> fairly abstract.
>
> I asked him to use objects and ArrayList. He is not used to the
> concept of object-oriented programming. So he sticks to the Array with
> those indexes. Each time when he asks me to help debug, it's a
> headache because I have to remember the indexes that reference to
> different things. All meaningless numbers pointed to by indexes.
>
> A question for you folks: Is it a good idea to use Array? Wouldn't it
> be better to use ArrayList instead?
>

My System SpecsSystem Spec
Old 08-04-2009   #3 (permalink)
Tom Dacon


 
 

Re: Usage of Array in C#.NET


"Curious" <fir5tsight@xxxxxx> wrote in message
news:a5676adb-3ea9-489a-8e43-ceb58407975e@xxxxxx
Quote:

>I have a colleague who used to program in S-PLUS. My impression about
> S-PLUS is that it's based on matrix calculations and consumes a lot of
> memory. It takes a long time to run a small program in S-PLUS.
>
> Now he wants to learn C# in order to speed things up. He simply uses
> Array in C#.NET (to resemble matrix in S-PLUS). He refers to
> everything in the Array by indexes, i.e., integer numbers. It seems
> fairly abstract.
>
> I asked him to use objects and ArrayList. He is not used to the
> concept of object-oriented programming. So he sticks to the Array with
> those indexes. Each time when he asks me to help debug, it's a
> headache because I have to remember the indexes that reference to
> different things. All meaningless numbers pointed to by indexes.
>
> A question for you folks: Is it a good idea to use Array? Wouldn't it
> be better to use ArrayList instead?
>
For matrix operations, performance is critical. Indexed array references are
typically the highest-performance way to do it, In general, this is a case
where object-oriented approaches just don't work out in practice because of
the inevitable overhead (please, no uninformed flames from the gallery on
this - it's well known to be true).

So if you're going to do his debugging for him, get comfortable with
multidimensional arrays. One thing you can do is ask him to rename the index
variables so that it's a little easier to visualize what the dimensions
mean.

However, indexed arrays are NOT necessarily the high-performance solution to
all problems he may be solving. There are places where the CLR types are
appropriate - for instance dictionaries for lookups, where the underlying
hashtable will beat a binary search on an array of keys.

It's not a certainty, by the way, that using C# will speed things up.
There's a good reason why Fortran, for instance, is still used heavily by
people who do compute-intensive math for a living. The optimizing
performance of Fortran compilers is legendary.

Good luck,
Tom Dacon


My System SpecsSystem Spec
Old 08-04-2009   #4 (permalink)
Curious


 
 

Re: Usage of Array in C#.NET

It's a financial application to read price and volume information for
a period of time for each security on the stock market from a huge
file.

Then based on the changes in price or volume during the recent days,
come up with a selection of securities.

I've created a program with a Security class, and ArrayList containing
a collection of Security instances. I've also created a method in the
Security class to do the calculation. Then I use Sort to sort the
ArrayList to come up with a list. It's fast, and straight-forward.

I still fail to understand why he doesn't accept the concept of object-
oriented programming.

Yes, he uses a lot of int[], double[], string[], etc. You have to go
to different Arrays to get different values for a same security. They
are not together.
My System SpecsSystem Spec
Old 08-04-2009   #5 (permalink)
Tom Dacon


 
 

Re: Usage of Array in C#.NET


"Curious" <fir5tsight@xxxxxx> wrote in message
news:628d40d7-76c3-41f6-a7fd-d5d0660cfd9f@xxxxxx
Quote:

> It's a financial application to read price and volume information for
> a period of time for each security on the stock market from a huge
> file.
>
> Then based on the changes in price or volume during the recent days,
> come up with a selection of securities.
>
> I've created a program with a Security class, and ArrayList containing
> a collection of Security instances. I've also created a method in the
> Security class to do the calculation. Then I use Sort to sort the
> ArrayList to come up with a list. It's fast, and straight-forward.
>
> I still fail to understand why he doesn't accept the concept of object-
> oriented programming.
>
> Yes, he uses a lot of int[], double[], string[], etc. You have to go
> to different Arrays to get different values for a same security. They
> are not together.
So profile your solution vs. his and see where the performance bottlenecks
are. If your object-oriented solution doesn't impose a significant penalty
(that is, your solution lies comfortably within the performance requirements
of the problem), then you've got a good case for using the CLR classes in
favor of his solution. Maintainability and understandability count for a
lot, as long as you haven't put a bullet in the head of the application
because of unacceptable performance.


Tom Dacon
Dacon Software Consulting




My System SpecsSystem Spec
Old 08-04-2009   #6 (permalink)
Smola


 
 

Re: Usage of Array in C#.NET

In article <628d40d7-76c3-41f6-a7fd-
d5d0660cfd9f@xxxxxx>, fir5tsight@xxxxxx
says...>
Quote:

> I still fail to understand why he doesn't accept the concept of
object-
Quote:

> oriented programming.
He's lazy, and he's got you.


--
de gustibus disputandum esse
My System SpecsSystem Spec
Old 08-04-2009   #7 (permalink)
Family Tree Mike


 
 

Re: Usage of Array in C#.NET

Curious wrote:
Quote:

>
> I still fail to understand why he doesn't accept the concept of object-
> oriented programming.
>
And I'm betting that the other programmer does not see why you want to
abandon S-PLUS. Until you show them why abandoning it 1) gives the same
answers, and 2) gets those answers faster, or more optimally, you've got
a hard sell.

Look at another point of view. They probably feel that their routine in
S-PLUS will not only solve your type of problem, but because the
matrices are generic, could also solve other problems. Your OO methods
and app are domain specific.

--
Mike
My System SpecsSystem Spec
Old 08-05-2009   #8 (permalink)
Cor Ligthert[MVP]


 
 

Re: Usage of Array in C#.NET

Curious

He should look at all the implementations of the Collection Generic
namespace not the arraylist.

http://msdn.microsoft.com/en-us/libr...ic(VS.80).aspx

Then he can simple make classes and make all his calculation with that.

Be aware that straight arrays, which are immutable can be the fastest as
long as they don't change after instancing.

Cor

"Curious" <fir5tsight@xxxxxx> wrote in message
news:a5676adb-3ea9-489a-8e43-ceb58407975e@xxxxxx
Quote:

>I have a colleague who used to program in S-PLUS. My impression about
> S-PLUS is that it's based on matrix calculations and consumes a lot of
> memory. It takes a long time to run a small program in S-PLUS.
>
> Now he wants to learn C# in order to speed things up. He simply uses
> Array in C#.NET (to resemble matrix in S-PLUS). He refers to
> everything in the Array by indexes, i.e., integer numbers. It seems
> fairly abstract.
>
> I asked him to use objects and ArrayList. He is not used to the
> concept of object-oriented programming. So he sticks to the Array with
> those indexes. Each time when he asks me to help debug, it's a
> headache because I have to remember the indexes that reference to
> different things. All meaningless numbers pointed to by indexes.
>
> A question for you folks: Is it a good idea to use Array? Wouldn't it
> be better to use ArrayList instead?
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Fast copy method of sub array (=array range) possible? VB Script
How to create array without quotes? $array = (a,b,c) PowerShell
Array indexing: Want to say "Item #2 through the rest of the array." PowerShell
Stupid Array Tricks: Initializing an Array to a Certain Size PowerShell
how to assign values to array and how to create array via variable PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46