We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 17,723 times

Contents

Downloads

Related Categories

Iteration Methods - Introduction

misfeldt

Introduction

Introduction

I’ve been implementing numerical libraries in .NET and have come to some conclusions about iteration performance. My classes have to hold a large amount of data and be able to iterate through that data as quickly as possible. In order to compare various methods, I created a simple class called Data that encapsulates an array of doubles.

Method #1: Enumeration

Data implements IEnumerable. It contains GetEnumerator which returns its own DataEnumerator, an inner class.


  public IEnumerator GetEnumerator()
   {
     return new DataEnumerator( this );
   }
   
   internal class DataEnumerator : IEnumerator
   {
     private Data internal_ = null;
     private int index = -1;

     public DataEnumerator( Data data )
     {
       internal_ = data;
     }

     public object Current
     {
       get
       {
         return internal_.Array[index];
       }
     }

     public bool MoveNext()
     {
       index++;
       if ( index >= internal_.Array.Length )
       {
         return false;
       }
       return true;
     }

     public void Reset()
     {
       index = -1;
     }
   }

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