Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 18,422 times

Contents

Downloads

Related Categories

Iteration Methods - More Methods

misfeldt

More Methods

Method #2: Indexing

I implemented an index operator on the class which simply calls the index operator on the array.

public double this[int position]
{
 get
 {
   return array_[position];
 }
}

Method #3: Indirect Array

I created a property to access the array.

public double[] Array
{
  get
  {
    return array_;
  }
}

When iterating, I called the Array property and then its index operator.

d = data.Array[j];

Method #3: Direct Array

I created a reference to the array.

double[] array = data.Array;

Then, I iterate through that reference.

d = array[j];

Method #4: Pointer Math

Finally, I tried improving performance by iterating through the array in Managed C++ using pointer manipulation.

static void iterate( Data& data )
{
 double d;
 double __pin* ptr = &( data.Array[0] );
 for ( int i = 0; i < data.Array.Length; i++ )
 {
   d = *ptr;
   ++ptr;
 }
}

I called it this way:

Pointer.iterate( data );

CEO of CenterSpace Software. We make numerical analysis class libraries for the .NET platform. Author of Elements of Java Style and Elements of C++ Style.

Comments

  • Accessing data

    Posted by misfeldt on 06 Aug 2003


    Thanks for the feedback! I tried putting in the extra step. The results are virtually unchanged from previous changes. Please try it out yourself.

    Cheers,
    Trevor

    --
    [email="misfeldt@cente...

  • Your Pointer Itteration is not correct

    Posted by aarora@onyxfund.com on 13 May 2003

    You are merely accessing the reference to where the data is kept for the array, but are never actually accessing the data, which you do elsewhere (for example Method #2). If you were to actually acces...