Library tutorials & articles
Iteration Methods
- Introduction
- More Methods
- Conclusions
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 );
Related articles
Related discussion
-
Help me how to dynamic create row column of TableLayoutpanel at run time ??????
by anatha1 (0 replies)
-
Very Urgent regarding deleting the images from a folder
by rameshbandi (2 replies)
-
How to Export Datagridview contents to Excel
by BarbaMariolino (8 replies)
-
Help accessing sound card
by daz4904 (0 replies)
-
How to Write a GPS Application
by stoyac (19 replies)
Related podcasts
-
Object-Oriented Programming in Ruby
In this episode, I talk with Scott Bellware about object-oriented programming in Ruby, and Ruby's object model. This is taken from a private conversation, and the audio quality suffers at times. Much thanks to Scott for allowing this to be released.This episode of the Alt.NET Podcast is bro...
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
Trevor Misfeldt
CEO, CenterSpace Software
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 access the data, then I think your method would perform similar to Method #2. I don't think that the actual data is read until you access the variable. So perhaps to complete the test, I would perform a d += 1 in each loop to make sure that the data is accessed by each method your base class in which the object exists.
This thread is for discussions of Iteration Methods.