Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Memory allocation in C++

Status
Not open for further replies.

Nosferatu

Programmer
Jun 9, 2000
412
RO
I have a question about memory management and allocation in C++.

I am implementing my version of DOM hierarchy (XML stuff, i hope someone
knows about this) and i have a HUGE memory problem.

I have implemented the hierarchy in a static library file (lib), using MSVC60.
The stress test for this is an XML file, "weighting" about 1.6 MB and
containing 200.000 elements. When i load it into my document object model classes,
the memory usage on my NT machine goes up to heaven and, for the debug
version of the library the hierarchy eats about 100 MB of memory,
simply driving me crazy! The test is made on a console app project, also in VC60.

For the release version of the library, the memory usage drops about 50%.
Still, this is HUGE amount of memory for storing a 1.6 MB file.

I have counted and measured object sizes one time and again and i cannot figure
out why does all that space gets occupied...

I know i'm a little blurry in my question, but i couldn't just paste the
class hierarchy here, given its size. Anyway, the folks who developed the DOM standard agree that
DOM implementations will have some memory problems to fight with. But, this
problem is tooooo big for me...

The vast majority of the objects are
Code:
<Element>
type objects,
which is a derived type from a
Code:
Node[/b] object. The size of an Element,
as returned by [b]sizeof[/b] is 64 bytes. 
thus,[COLOR=blue] 64 * 200000 = 12.800.000[/color], about 12 Megs... far enough from 100 MB.

I stripped all the [b]virtuals[/b] automaticly included by MSVC and i don't use any
virtual functions, so the VTable is empty. 
So, could anybody tell me [b][COLOR=green] WHERE ALL THAT MEMORY GOES?[/color][/b]

Does anybody have any idea? Its not about memory leaks, i wonder if i am missing something
when using static libraries in other projects...

Heeeelp, somebody, please!!!  [b][red]Nosferatu[/red][/b]
We are what we eat...
There's no such thing as free meal...
 
P.S.

The worse case scenario for the Node class would be for a size of 140 bytes, when all its pointers are allocated (i counted the size of the pointed objects as well).
Still,
140 * 200.000 = 28MB, which is still way under 100 Mb...

help again... millions of thanks to the one who can help me understand this or give me just a small clue... [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
 
Have you investigated one of the tools like SmartHeap?

Chip H.
 
No, but thanks anyway. I just downloaded it and i will try to see how it works and if there is anything that i could pull out from it...
But, as far as i seen on their webpage, this program manages efficiently the access to the heap, how would that have anything to do with the memory over-allocation that i presume is happening? Anyway, thanks, i will try it out... [red]Nosferatu[/red]
We are what we eat...
There's no such thing as free meal...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top