finding the memory footprint of DOMDocument

Discussion in 'XML' started by muralibala68@gmail.com, Oct 7, 2006.

  1. Guest

    Hi,

    Is there a way to find the total size of the DOMDocument created using
    xerces C++ API (without serializing it) ?

    Thanks.
    , Oct 7, 2006
    #1
    1. Advertising

  2. wrote:
    > Hi,
    >
    > Is there a way to find the total size of the DOMDocument created using
    > xerces C++ API (without serializing it) ?
    >
    > Thanks.


    Peace,

    I'm working on the same problem myself. I've got an interesting piece
    of software in development to compare the different parsers to see the
    time taken and memory footpaths of the built DOM's. I figured out a
    way to use java.lang.Runtime to get memory details of the JVM to
    indirectly assert out the size, but, this is NOT an ABSOLUTE method.
    Meanwhile, I've happened across the following code and you may be able
    to apply it, as I intend to myself for the same reaon in a few days.
    Just haven't had the time to study the code yet. Let me know how it
    comes along, eh....

    public class Sizeof
    {
    public static void main (String [] args) throws Exception
    {
    // Warm up all classes/methods we will use
    runGC ();
    usedMemory ();

    // Array to keep strong references to allocated objects
    final int count = 100000;
    Object [] objects = new Object [count];

    long heap1 = 0;

    // Allocate count+1 objects, discard the first one
    for (int i = -1; i < count; ++ i)
    {
    Object object = null;

    // Instantiate your data here and assign it to object

    object = new Object ();
    //object = new Integer (i);
    //object = new Long (i);
    //object = new String ();
    //object = new byte [128][1]

    if (i >= 0)
    objects = object;
    else
    {
    object = null; // Discard the warm up object
    runGC ();
    heap1 = usedMemory (); // Take a before heap snapshot
    }
    }

    runGC ();
    long heap2 = usedMemory (); // Take an after heap snapshot:

    final int size = Math.round (((float)(heap2 - heap1))/count);
    System.out.println ("'before' heap: " + heap1 +
    ", 'after' heap: " + heap2);
    System.out.println ("heap delta: " + (heap2 - heap1) +
    ", {" + objects [0].getClass () + "} size = " + size + "
    bytes");

    for (int i = 0; i < count; ++ i) objects = null;
    objects = null;
    }

    private static void runGC () throws Exception
    {
    // It helps to call Runtime.gc()
    // using several method calls:
    for (int r = 0; r < 4; ++ r) _runGC ();
    }

    private static void _runGC () throws Exception
    {
    long usedMem1 = usedMemory (), usedMem2 = Long.MAX_VALUE;
    for (int i = 0; (usedMem1 < usedMem2) && (i < 500); ++ i)
    {
    s_runtime.runFinalization ();
    s_runtime.gc ();
    Thread.currentThread ().yield ();

    usedMem2 = usedMem1;
    usedMem1 = usedMemory ();
    }
    }

    private static long usedMemory ()
    {
    return s_runtime.totalMemory () - s_runtime.freeMemory ();
    }

    private static final Runtime s_runtime = Runtime.getRuntime ();

    } // End of class
    Codedigestion, Oct 9, 2006
    #2
    1. Advertising

  3. Codedigestion wrote:
    > wrote:
    > > Hi,
    > >
    > > Is there a way to find the total size of the DOMDocument created using
    > > xerces C++ API (without serializing it) ?
    > >
    > > Thanks.

    >
    > Peace,
    >
    > I'm working on the same problem myself. I've got an interesting piece
    > of software in development to compare the different parsers to see the
    > time taken and memory footpaths of the built DOM's. I figured out a
    > way to use java.lang.Runtime to get memory details of the JVM to
    > indirectly assert out the size, but, this is NOT an ABSOLUTE method.
    > Meanwhile, I've happened across the following code and you may be able
    > to apply it, as I intend to myself for the same reaon in a few days.
    > Just haven't had the time to study the code yet. Let me know how it
    > comes along, eh....
    >
    > public class Sizeof
    > {
    > public static void main (String [] args) throws Exception
    > {
    > // Warm up all classes/methods we will use
    > runGC ();
    > usedMemory ();
    >
    > // Array to keep strong references to allocated objects
    > final int count = 100000;
    > Object [] objects = new Object [count];
    >
    > long heap1 = 0;
    >
    > // Allocate count+1 objects, discard the first one
    > for (int i = -1; i < count; ++ i)
    > {
    > Object object = null;
    >
    > // Instantiate your data here and assign it to object
    >
    > object = new Object ();
    > //object = new Integer (i);
    > //object = new Long (i);
    > //object = new String ();
    > //object = new byte [128][1]
    >
    > if (i >= 0)
    > objects = object;
    > else
    > {
    > object = null; // Discard the warm up object
    > runGC ();
    > heap1 = usedMemory (); // Take a before heap snapshot
    > }
    > }
    >
    > runGC ();
    > long heap2 = usedMemory (); // Take an after heap snapshot:
    >
    > final int size = Math.round (((float)(heap2 - heap1))/count);
    > System.out.println ("'before' heap: " + heap1 +
    > ", 'after' heap: " + heap2);
    > System.out.println ("heap delta: " + (heap2 - heap1) +
    > ", {" + objects [0].getClass () + "} size = " + size + "
    > bytes");
    >
    > for (int i = 0; i < count; ++ i) objects = null;
    > objects = null;
    > }
    >
    > private static void runGC () throws Exception
    > {
    > // It helps to call Runtime.gc()
    > // using several method calls:
    > for (int r = 0; r < 4; ++ r) _runGC ();
    > }
    >
    > private static void _runGC () throws Exception
    > {
    > long usedMem1 = usedMemory (), usedMem2 = Long.MAX_VALUE;
    > for (int i = 0; (usedMem1 < usedMem2) && (i < 500); ++ i)
    > {
    > s_runtime.runFinalization ();
    > s_runtime.gc ();
    > Thread.currentThread ().yield ();
    >
    > usedMem2 = usedMem1;
    > usedMem1 = usedMemory ();
    > }
    > }
    >
    > private static long usedMemory ()
    > {
    > return s_runtime.totalMemory () - s_runtime.freeMemory ();
    > }
    >
    > private static final Runtime s_runtime = Runtime.getRuntime ();
    >
    > } // End of class


    OOPS, you mentioned C++ - This is Java Code... SORRY!
    Codedigestion, Oct 9, 2006
    #3
  4. wrote:
    > Hi,
    >
    > Is there a way to find the total size of the DOMDocument created using
    > xerces C++ API (without serializing it) ?
    >
    > Thanks.


    I believe there's a method available called, sizeOf() which would do it
    for you.
    Codedigestion, Nov 3, 2006
    #4
  5. Codedigestion wrote:
    > I believe there's a method available called, sizeOf() which would do it
    > for you.


    Not according to http://xml.apache.org/xerces-c/apiDocs/functions.html
    and I don't see anything else in there which will directly tell you this.

    Since the memory manager for Xerces is a plug-in API, you could try
    supplying an instrumented version thereof and see how many bytes are
    being allocated and deallocated. Remember to consider alignment issues,
    which will depend the platform, compiler, and compiler settings.




    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Nov 3, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Beatrice Rutger

    JMS memory footprint size

    Beatrice Rutger, Jun 5, 2005, in forum: Java
    Replies:
    0
    Views:
    344
    Beatrice Rutger
    Jun 5, 2005
  2. gbrun
    Replies:
    1
    Views:
    441
    Andrey Kuznetsov
    Feb 19, 2006
  3. Adam Warner

    Memory footprint of a subclass

    Adam Warner, Feb 27, 2006, in forum: Java
    Replies:
    3
    Views:
    616
    Adam Warner
    Feb 27, 2006
  4. Replies:
    9
    Views:
    1,093
    nibblix
    Apr 24, 2006
  5. nick
    Replies:
    58
    Views:
    1,898
    Bart van Ingen Schenau
    Mar 16, 2009
Loading...

Share This Page