C
Chris Berg
I often wonder: Does it make any difference in EXECUTION TIME which
version I choose:
#1:
String st;
while (true){
st=dis.readLine();
if (st==null) break;
< do something else >
}
#2:
while (true){
String st=dis.readLine();
if (st==null) break;
< do something else >
}
It's obvious that st is valid outside the loop in #1. But does it get
allocated on the stack for every iteration in #2, or just re-used? If
not, I suppose #2 is preferred as far as limiting the scope, enabling
gc, is an issue.
Chris
version I choose:
#1:
String st;
while (true){
st=dis.readLine();
if (st==null) break;
< do something else >
}
#2:
while (true){
String st=dis.readLine();
if (st==null) break;
< do something else >
}
It's obvious that st is valid outside the loop in #1. But does it get
allocated on the stack for every iteration in #2, or just re-used? If
not, I suppose #2 is preferred as far as limiting the scope, enabling
gc, is an issue.
Chris