John,
Thanks for the feedback. Memory allocation should not occur in either example because the object declaration is a "placeholder" (for lack of a better term) for the object reference of the current iteration object. What I am wondering is how much overhead is needed for variable definition? Is it nonexistent because the class is already in the JVM's Class Loader?
Stacy.
| "John Ghidiu" <[EMAIL PROTECTED]>
06/21/2002 01:19 PM
|
To: "JDJList" <[EMAIL PROTECTED]> cc: Subject: [jdjlist] RE: JVM Overhead |
Stacy,
I would think that there would be, as the first example declares a new instance of MyObject every iteration, which I believe will allocate memory on every pass, whereas the second example will not. However, I cannot say for certain that the compiler will optimize this. Perhaps a simple benchmark would be the best solution?
Regards,
John
John Ghidiu
Benderson Development Company Inc.
[EMAIL PROTECTED]
(716) 878-9376
-----Original Message-----
From: Stacy C. May [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 21, 2002 13:39
To: JDJList
Subject: [jdjlist] JVM Overhead
Is there a difference in JVM overhead/expense the following code? and why?
public void someMethod(List passedList) {
Iterator iter = passedList.iterator();
while (iter.hasNext()) {
MyObject myObject = (MyObject)iter.next();
// do some processing on myObject
}
}
compared to:
public void someMethod(List passedList) {
Iterator iter = passedList.iterator();
MyObject myObject = null;
while (iter.hasNext()) {
myObject = (MyObject)iter.next();
// do some processing on myObject
}
}
Thanks in advance.
Nj�™zŠ��z†�i��0�̬r‰ܢo�j��–+-
To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm
To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm
