Is there any difference in this code? If there is an SomeObject array called array... SomeObject object = null; for (int i = 0; i < array.length; i++) { object = array[i]; ...some processing... } or........ for (int i = 0; i < array.length; i++) { SomeObject object = array[i]; ...some processing... }
John Lee
Ranch Hand
Joined: Aug 05, 2001
Posts: 2545
posted
0
Originally posted by Aaron Webb: Is there any difference in this code? If there is an SomeObject array called array... SomeObject object = null; for (int i = 0; i < array.length; i++) { object = array[i]; ...some processing... } or........ for (int i = 0; i < array.length; i++) { SomeObject object = array[i]; ...some processing... }
I think no. 2 is wrong, you have to declare before the loop.
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
Either form is acceptable. The second form creates a bunch of unneeded pointers but since they are on the stack and not the heap, it isn't a big deal.
both are correct and work fine i just didn't know if there was a performance difference one way or the other
Aaron Webb
Greenhorn
Joined: Aug 16, 2001
Posts: 17
posted
0
cool thats what i was wondering...thanks
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
posted
0
Originally posted by Aaron Webb: both are correct and work fine i just didn't know if there was a performance difference one way or the other
Well, did you try to benchmark the two? That would give you the only authentic answer...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Divya Venkatesh
Greenhorn
Joined: Nov 05, 2002
Posts: 28
posted
0
How do you benchMark? Is it Just a way of checking how much time each loop takes.Do you do it using time functions.? Or is there someother method to do this? Thanks.