• Post Reply Bookmark Topic Watch Topic
  • New Topic

static fields and methods  RSS feed

 
Mark Herschberg
Sheriff
Posts: 6037
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are static fields and methods actually stored by a JVM. I know the principle, can anyone give me specifical machanics?
Is accessing static fields and methods faster? (If so, then single objects could use statics for faster performance.)
--Mark
hershey@vaultus.com
 
Jim Baiter
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a field_info struct described the VM spec that
has a member access_flags. The constant ACC_STATIC = 0x0008
is used to indicate the field is static. I put the link for
this in the spec below. I doubt you really gain much performance
from statics except that possibly you can avoid unnecessary
construction in a few cases. However, if by "single" you mean
"singleton", then you don't avoid any construction since you
are only creating a single instance of the field in your
singleton object. I would also be very wary of a design that
is using static for performance reasons. A static member should
really be static in nature.
http://java.sun.com/docs/books/vmspec/html/ClassFile.doc.html#2877
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!