• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

About performance and memory usage

 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
If I use an object with a lot of getters and setters (e.g 100) instead of an object with just 1 getter and 1 setter, is it poor in performance and memory usage? (At runtime, only 1 getter and 1 setter will be called on each object).
Thanks,
Jack
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand your question.
Moving this to the Performance forum...
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also have no idea what you're asking. Perhaps a little bit of code to illustrate how having one getter and 100 getters could be alternate implementations of the same class?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ernest Friedman-Hill:
I also have no idea what you're asking. Perhaps a little bit of code to illustrate how having one getter and 100 getters could be alternate implementations of the same class?


Alternative 1 (one getter/setter):

Alternative 2 (n getter/setter):

Not very clever and elegant perhaps (it depends on the context i think)
but these code fragments are alternative implementations for the same
class.
I think the question of Jack is if the number of methods of a class has
any impact to the performance. I think the number of methods influences
only the size of the class file (and so the time needed to load the class)
and the size of the vtable (but this should not influence performance).
I hope this helps
Stephan
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jack,
If the getters and setters are just getting/setting a field, there shouldn't be a performance difference. (or if there is it would be tiny)
However, the getters/setters are transferring data across a network, it is better to make one call. This happens in frequently in EJBs.
 
I'm all tasted up for a BLT! This tiny ad wants a monte cristo!
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic