aspose file tools*
The moose likes Java in General and the fly likes what is the size of an object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "what is the size of an object?" Watch "what is the size of an object?" New topic
Author

what is the size of an object?

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
can anyone tell me the size of an object
as premitives got the size why dont objects have some constant value(size)?


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

You mean the number of bytes that an object takes up in memory?

There's no way to find that out in the standard Java API. Java does not have a "sizeof" operator, like you have in C and C++.

Note that the size of an object in memory depends on the particular implementation of the JVM you are using. It might be different for the Sun JVM on Windows and the HP JVM on HP-UX, for example.

If you really are desperate to find this out in your Java application, I think there is a way to find out how many bytes an object takes up via the debugger API, but that API is not easy to use.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ela Jha
Greenhorn

Joined: Jul 17, 2006
Posts: 12
How can objects have predefined size as it really depends on the number and type of instance variable it holds.
[ August 23, 2006: Message edited by: Ela Jha ]
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Originally posted by saikrishna cinux:
can anyone tell me the size of an object
as premitives got the size why dont objects have some constant value(size)?


Dear Saikrishna,

You can use the code below:




Here is the Interpreter class :


Now you compile both class and try to run like following



Hope this helps you out.


The Best way to predict your future is to create it - Every great individual common man
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Alternatevely check this link ..

This may be usefull for you.

Do you know your data size?
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
thank's a lot for your code
but if any one ask me about the object size what should tell them?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
Tell them the question does not have a simple answer.

Bill


Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the size of an object?
 
Similar Threads
object
instance of class
Is there a limit to the size of object that can be kept in a session?
Maximum size of Java Object
Object Size