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 please for student
by mandy130 (0 replies)
-
Loop help needed
by BKRoberts (5 replies)
-
Problem after strong naming an assembly
by rinkurathor1 (0 replies)
-
Regarding User control creation in C# .Net(Windows Application)
by porchelvi (0 replies)
-
Access Database Refreshing
by ranjithmadawala (0 replies)
Related podcasts
-
Looking into the C# Crystal Ball with Charlie Calvert and Bill Wagner
One of the most exciting announcements from PDC was the news about C# 4.0 and Visual Studio 2010. With all the excitement and discussion throughout the event about these new developer tools, we reached out to two experts in the fields. Charlie Calvert and Bill Wagner sat down with Keith and Woody...
Events coming up
-
Dec
6
Developing AJAX Web Applications with Castle Monorail
London, United Kingdom
Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!
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.