473,408 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

finding the memory footprint of DOMDocument

Hi,

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

Thanks.

Oct 7 '06 #1
4 1752

mu**********@gmail.com 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 [i] = 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 [i] = 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

Oct 8 '06 #2

Codedigestion wrote:
mu**********@gmail.com 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 [i] = 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 [i] = 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!

Oct 9 '06 #3

mu**********@gmail.com 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.

Nov 2 '06 #4
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
Nov 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Peretz | last post by:
I am trying to optimize my C# program, but no matter what I try the application keeps eating memory. I verified all the references and even got special software to count references. I made sure all...
6
by: Tom | last post by:
We have a VERY simple .NET C# Form Application, that has about a 23MB Memory Footprint. It starts a window runs a process and does a regular expression. I have done a GC.Collect to make sure that,...
2
by: assi | last post by:
Hello all We are developing a large dotnet application, which includes ~ 120 assemblies. (total size of all binaries is ~ 20MB). Our application also references the following dotnet assemblies:...
1
by: Derrick | last post by:
Thanks to many on this newsgroup, I now have a prototype Windows Forms C# app that reads xml documents into DataSets via XmlDataDocument, and does *stuff* with it. I basically have about 25 megs...
1
by: Derrick | last post by:
I am reading in xml files that equate to sql tables, via XmlDataDocument, and then operating on the DataSet. With the most simple app that just loads the xml doc, I see the memory footprint of the...
8
by: Bob Dufour | last post by:
We got a windows form application that we wrote in VB.Net. Essentially its a manager for a list of persons and their contacts and some other info about the persons. No rocket science but lots of...
9
by: Bruno Barberi Gnecco | last post by:
I'm using PHP to run a CLI application. It's a script run by cron that parses some HTML files (with DOM XML), and I ended up using PHP to integrate with the rest of the code that already runs the...
9
by: neil.johnston | last post by:
I have a cut down example program that uses multiset to order some data. The data arrives from various sources and has a time stamp, data with identical timestamps can arrive and due to fifo's and...
6
by: rupert.thurner | last post by:
what would be a good means of finding where the 0.11 version of edgewall trac uses excessive memory. see http://groups.google.com/group/trac-dev/browse_thread/thread/116e519da54f16b for some...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.