Well, you can go the route of serializing the object out as suggested by another.

Or, if you just need a approximate calculation (since we don't know WHY you need the size), then add a size() method to both classes that calculates the size of a particular instance of said class.  Basically, LDIFData is a collection of Strings and one long.  A long primitive is 8 bytes.  Each instance of the class can just calculate using the length of each String.

Dennis




Navjot Singh <[EMAIL PROTECTED]>

07/08/2004 12:46 PM

Please respond to
"Struts Users Mailing List" <[EMAIL PROTECTED]>

To
Struts Users Mailing List <[EMAIL PROTECTED]>
cc
Subject
Re: [OT] how to calculate the size of an object





hi,

Thanks for the link but this is very naive way of doing it. I am leaving
it to the mercy of gc.

What this method is doing

1. run gc() manually (AND hope it wont run automatically again soon.)
2. free memory
3. create and object.
4. free memory

and now just wish that JVM wont allocate any memory in it's heap between
steps 2 & 4. so that one can assume that whatsoever output comes belongs
to my object. I am at something better.

Jim you are absolutely right, this technique may return a negative number.

navjot singh


[EMAIL PROTECTED] wrote:

>
> http://www.google.com/search?hl=en&lr=&ie=UTF-8&q=size+java+object
>
> The first one looks promising.
>
> Dennis
>
>
>
>
> *Navjot Singh <[EMAIL PROTECTED]>*
>
> 07/08/2004 11:57 AM
> Please respond to
> "Struts Users Mailing List" <[EMAIL PROTECTED]>
>
>
>                  
> To
>                  Struts Users Mailing List <[EMAIL PROTECTED]>
> cc
>                  
> Subject
>                  [OT] how to calculate the size of an object
>
>
>                  
>
>
>
>
>
> hi,
>
> I use SAX parser to load an LDIF file into memory. Whatsoever data i
> read, i fill into an object.
>
> I need to know *the size of LDIFData object* at runtime. How to do that?
>
> Well the class structure is something like this
>
> public class LDIFData{
>                 ArrayList cards; // collection of Card
>                 String filename;
>                 long lastLoadedTime;
> }
>
> public class Card{
>                 String name;
>                 String email
>                 String mobile;
> }
>
> --
> regards
> Navjot Singh
>
> When you jump for joy, beware that no-one moves the ground from beneath
> your feet. -- Stanislaw Lem, "Unkempt Thoughts"
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

--
regards
Navjot Singh

When you jump for joy, beware that no-one moves the ground from beneath
your feet. -- Stanislaw Lem, "Unkempt Thoughts"

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to