Re: sizeof in java! need help



Hi,

Thomas Weidenfeller wrote:
i have one doubt. java does not have sizeof(). so how can i know the
size of the objects in java.

You don't need it. It's that simple.

Well, the shallow size is quite simple.

But how about the "deep size" - that's nontrivial! (*)

Ciao,
Ingo

(*) It's trivial to write a reflection-based method that gets the deep size, but normally, you do not really want the deep size, but something between the flat size and the deep size (**). And that is *very* non-trivial.

(**) Mostly, you want to know the size of the object itself plus (recursively) the size of the referenced objects that are not (***) referenced by other references. :-)

(***) Except they are referenced by Objects within the same graph.

Pheww - example:


A
/ \
B C
/ | \ \
D | E \
\ | \ /
F G

Now, the "expected" sizes are (as sum of flat size):

A: A+B+C+D+E+F+G
B: B+D+E+F (and not G - or perhaps "sizeof(G)/2"?)
C: C (...)
D: D (...)
E: E (...)
F: F
G: G

Note that this is in no way 'transitive'!

Ciao,
Ingo

.



Relevant Pages

  • Re: Custom Surrogate
    ... I need to do a deep copy of my object but I do NOT want to copy the objects ... The MemberwiseClone method creates a shallow copy by creating a new ... consider an object called X that references objects A and B. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: "deep copy" with VisualWorks?
    ... references or pointers to objects in the copied array. ... then I tried "dcopy," which seemed to do the trick, although it has ... some strange reference in the comment to creating a "smart deep copy," ...
    (comp.lang.smalltalk)
  • Re: Deep Copying Techniques?
    ... Any arbitrary object may itself have references to objects that don't ... provide deep copies of themselves. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... "Steve - DND" wrote in message ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Returning array: reference or deep copy?
    ... > Ryan Stewart wrote: ... >> Always references. ... If you want a copy (deep or shallow), ...
    (comp.lang.java.programmer)
  • Re: WARNING! SUPER MAJOR SPOILERS IN THE ABOVE POST!!!!!!!!!!!!!!!!!!!!!!
    ... title changes but the "References" header is set, ... browse the group in flat rather than threaded style? ...
    (rec.arts.anime.misc)