hi all! > 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.
yes. because it is not an "object declaration" but the declaration of a
variable that may hold a reference of the stated type ("Object" in that case).
objects are *only* created by "new", never by the declaration of a reference
variable (this is quite a common misunderstanding with former C++
programmers)
> 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?
local variables are normally allocated on the stack. this should not
introduce a lot of overhead. but it has nothing to do with the fact wether the class
is already loaded or not.
moreover, the compiler might optimize by doing implicitely exactly what you
did - declare the variable once, not inside the loop in every iteration. i
did not read the VM-specs into that deep ;o) perhaps someone knows about the
exact way in which this is treated by the compiler...
greetings
> Stacy.
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
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
To change your membership options, refer to: http://www.sys-con.com/java/list.cfm
