M
Mountain Bikn' Guy
It turns out that there is indeed a simple solution (at least for the first
half of the problem) and that .NET can indeed add correctly![Wink ;) ;)](/styles/default/custom/smilies/wink.gif)
In the statements that generate the brute force sum code (the line 1 + 2 +
.... + n), all I did was add this:
if ((i % 200) == 0)
{
wrtr.WriteLine();
}
This breaks the lines of code into shorter lines. Now the reflection
invocation produces the correct result too.
I find it strange that my csc log file (compiler.out) did not issue any
warning about the lines being too long -- and that the program compiled and
ran and produced incorrect results -- all with no warning.
(I also find it frustrating that Jesse Liberty didn't check the code in his
book more carefully... but I'll withhold judgement until after I've written
a book or two myself and experienced the difficulty I imagine exists in
getting all the examples correct.)
However, I am happy that this was not a serious issue... but there is still
a second part to this puzzle.
1. In my second example (see first post in this thread), that "optimized"
code is always about 5 times slower than the normal looping code.
2. In the second example, the lines are not too long, so we don't have the
problem we had in this first example. However, if the number of rows in that
approach brute force are increased above about 500, then that code refuses
to run via reflection. If anyone is interested, I'll post the rest of that
code too.
Dave
half of the problem) and that .NET can indeed add correctly
![Wink ;) ;)](/styles/default/custom/smilies/wink.gif)
In the statements that generate the brute force sum code (the line 1 + 2 +
.... + n), all I did was add this:
if ((i % 200) == 0)
{
wrtr.WriteLine();
}
This breaks the lines of code into shorter lines. Now the reflection
invocation produces the correct result too.
I find it strange that my csc log file (compiler.out) did not issue any
warning about the lines being too long -- and that the program compiled and
ran and produced incorrect results -- all with no warning.
(I also find it frustrating that Jesse Liberty didn't check the code in his
book more carefully... but I'll withhold judgement until after I've written
a book or two myself and experienced the difficulty I imagine exists in
getting all the examples correct.)
However, I am happy that this was not a serious issue... but there is still
a second part to this puzzle.
1. In my second example (see first post in this thread), that "optimized"
code is always about 5 times slower than the normal looping code.
2. In the second example, the lines are not too long, so we don't have the
problem we had in this first example. However, if the number of rows in that
approach brute force are increased above about 500, then that code refuses
to run via reflection. If anyone is interested, I'll post the rest of that
code too.
Dave
Mountain Bikn' Guy said:I pasted the complete program to a message in this thread just above. The
example comes from Jesse Liberty's Programming C#. The main issue/problem
seems to be reflection (which is my main interest in working with this type
of code anyway.) All I did was debug his example code so it would compile
and run, and then I added a method to check the results. The method I added
just contains the code Jesse was producing at runtime. I copied the result
into the main file and I run it without reflection. Under those conditions
it produces the correct result. When invoked via reflection it produces a
vastly incorrect result. I'm beginning to think there is an obvious solution
to this. In fact, I'm going to try putting line breaks into the generated
code to shorten the line length... I'll post the results.