>I guess that's a hard question: How to guess the memory consumption of
>a Java object? Probably, that depends on the Java virtual machine and
>on the operating system.
see http://mindprod.com/jgloss/sizeof.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Ulrich Scholz a écrit :
> I guess that's a hard question: How to guess the memory consumption of
> a Java object? Probably, that depends on the Java virtual machine and
> on the operating system.
>
> Lets first assume no inheritance and simple data types only. Maybe
> there's a number for that.
http://martin.nobilitas.com/java/sizeof.html
> I guess that's a hard question: How to guess the memory consumption of
> a Java object? Probably, that depends on the Java virtual machine and
[quoted text clipped - 6 lines]
>
> Ulrich
Besides the other links already posted, let me point you to the Java
Specialists Newsletter, issue 142: http://www.javaspecialists.eu/archive/Issue142.html
Check out the other newsletters while you're there... some are pretty
fun to read or experiment with.
Lew - 11 Sep 2007 14:55 GMT
>> I guess that's a hard question: How to guess the memory consumption of
>> a Java object? Probably, that depends on the Java virtual machine and
[quoted text clipped - 12 lines]
> Check out the other newsletters while you're there... some are pretty
> fun to read or experiment with.
Roedy's is the better link. The nobilitas.com link leaves out a lot, like
that the size of an object can vary during runtime and even reduce to zero.
Roedy's doesn't mention that either, but it hints at it when it points out,
> A JVM is free to store data any way it pleases internally, big or little endian, with any amount of padding or overhead, though primitives must behave as if they had the official sizes.
What neither link mentions is the influence of run-time optimization.

Signature
Lew
>I guess that's a hard question:
There are no hard questions. The answers* are a
different matter.
>..How to guess the memory consumption of
>a Java object?
I will ask you a question back.
Why? What is the end purpose of the task?
Try and answer that in terms of "I want to offer the
end user X". Where X is something the end user
might actually care about.
So that might include 'protection of crashing
from lack of memory', or 'warning of low memory',
but most users do not care how 'big' any individual
Java object might consume within the memory
space that the Java application is assigned.
From the developer's POV, it is better to not worry
about the memory size of objects unless/until it
becomes a problem, then it would be best to use
a profiler to determine what the problem is.
...
>Lets first assume no inheritance and simple data types only. Maybe
>there's a number for that.
(shrugs) 37. (* Also note that WAG's and sarcastic
answers are easy.)

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Lew - 11 Sep 2007 15:16 GMT
Ulrich Scholz wrote:
>> Lets first assume no inheritance and simple data types only. Maybe
>> there's a number for that.
> (shrugs) 37. (* Also note that WAG's and sarcastic
> answers are easy.)
There's no such thing as a Java program with "no inheritance".

Signature
Lew
~kurt - 12 Sep 2007 03:21 GMT
>>I guess that's a hard question:
>
> There are no hard questions. The answers* are a
> different matter.
I don't know - I've spent years trying to determine the correct question
for some problems in the past - and then the answer was easy....
- Kurt
Andrew Thompson - 12 Sep 2007 04:18 GMT
>>>I guess that's a hard question:
>>
[quoted text clipped - 3 lines]
>I don't know - I've spent years trying to determine the correct question
>for some problems in the past ..
(Dismissive) Puhh.. Sounds like philosophy to me.
In any case "What is the correct question?" (..is the
'easy' question that fits my hastily constructed, and
poorly thought out, theory of questions.)
>...- and then the answer was easy....
'Question the answer', anyone? ;-)

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Ulrich Scholz - 12 Sep 2007 13:31 GMT
Thanks for all replies.
> I will ask you a question back.
>
[quoted text clipped - 3 lines]
> end user X". Where X is something the end user
> might actually care about.
In some very few words:
Within the project MUSIC (www.ist-music.eu) I work on a method to
automatically adapt and distribute applications of many users on many
devices (http://www.eml-d.de/english/homes/scholz/Arbeiten/
divide_and_conquer-ESSPE07.pdf). We consider small devices.
This requires to map from the properties of an application, e.g.,
ressorce usage, onto user happiness (utility). Memory is a ressource.
For the relevant parts of applications we ask the application
developer to help us, i.e., the adaptation mechanism. That means: She
writes the utility function by hand. But for some trivial cases it
would be nice to lift some weight from her shoulders. Here comes in
my question.
OK?