struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "simarjit singh" <simarjit.si...@patni.com>
Subject RE: [OT] how to calculate the size of an object
Date Fri, 09 Jul 2004 04:13:23 GMT
With ByteArrayOutputStream approach, writeObject Method is also serializing
the object. Ofcourse serialization doesn't give size as it is more of a meta
data for the entire web of objects associated with the serialized object.

Rather than writing serialized object on file we  are putting it in a byte
array stream.

What u are getting is NOT bytes for object but bytes for serliazed data


Correct me if i am wrong...

-Simar



-----Original Message-----
From: Erik Weber [mailto:erikweber@mindspring.com]
Sent: Thursday, July 08, 2004 10:57 PM
To: Struts Users Mailing List
Subject: Re: [OT] how to calculate the size of an object


Also remember that when you serialize an Object (if I am not mistaken),
all the Objects referred to by that Object get serialized too (unless
the references are transient). In addition, there is serialization
overhead (protocol info that is not actually part of your Object but
that is required to deserialize). Your returned size could be misleading
if you have references to, say, some "parent" Object(s) in LDIFData, or
a ton of serialization overhead (unlikely).

Erik



Erik Weber wrote:

> public static long getSize(LDIFData data) {
> try {
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> ObjectOutputStream out = new ObjectOutputStream(baos);
> out.writeObject(data);
> out.close();
> return baos.toByteArray().length;
> }
> catch (Exception e) {
> e.printStackTrace();
> return -1;
> }
> }
>
> John Moore wrote:
>
>> Navjot Singh wrote:
>>
>>>
>>> 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;
>>> }
>>>
>> Off the top of my head...
>>
>> Serialize it to a byte array output stream, see how many bytes you have
>>
>> John
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message