Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Size of the Object

 
Dharmendra Kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody help me to find the size of the object in Java. Is there any methods to find this.
Thanks
Dharam
 
gautam shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dharam:
Can anybody help me to find the size of the object in Java. Is there any methods to find this.
Thanks
Dharam

i have seen the ans of this question at Sun's site in one of the qow. because of the fact i am very poor in writing so i can't explaint that here.just go there and find that qow.
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dharam,

Please change your name to be compliant with JavaRanch's naming policy.
Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name.
Thanks,
Cindy
Also, if you use the search function you will find lots of references to this topic.
For instance there was a good conversation here.
 
Doanh Nguyen
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would write it to a temporary file, then use the File length() method.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doanh
Your method can do the estimation, but not accurate. There is no way to accurately measure the size of object in Java as C sizeof() method. I guess that is intentional to hide some poor memory management problem in Java. Another thing is different JVM can have different implementation as well as different sizes.
Read here to know a little more, a little old, but still useful:
The Java IAQ:Infrequently Answered Questions
Need Java real project experience? Join our project team here!
 
Dharmendra Kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
Thanks for the information and the links provided.
Thanks
Dharmendra
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic