From: klaus triendl on
Hi,

I have a problem allocating memory in a c++ application for a 125MB xml
string that I retrieved first out of a MSXML2::IXMLDOMDocument or
MSXML2::IMXWriter (using msxml4 and msxml6).

Note that this is probably not a msxml-specific problem since the error
doesn't necessarily occur in msxml6; (besides I posted a message to the
xml newsgroup some weeks ago).
The problem rather depends on the size of the memory to be allocated.

All memory allocation functions return or throw an error:

- SysAlloc(): There is not enough storage to complete this operation
- new wchar_t: throws bad_alloc
- HeapAlloc(): throws error 17 - Not enough quota


I don't know much about virtual, paged and nonpaged memory and that
stuff, but I guess that it has to do something with this.

Even the Task Manager is probably not a reliable source, it reveals that
my 1GB of RAM is far from being consumed at the point of error.
If I allocate 1GB of RAM in a test program by allocating several times
125MB then this test program doesn't throw an error.


Does anybody have an idea what's going on and how I can solve this problem?
Thanks for any information!

--
Klaus Triendl
From: Skywing [MVP] on
I would suspect that you are seeing address space fragmentation. Can you
try giving the output of `!address' from WinDbg on your program when the
allocations are failing?

BTW, in my experience, for extremely large allocations it tends to be better
to go directly to the VirtualAlloc APIs and not the heap manager APIs.

--
Ken Johnson (Skywing)
Windows SDK MVP

"klaus triendl" <triendl.kj(a)m-box.at> wrote in message
news:%230y0bK0qGHA.3908(a)TK2MSFTNGP05.phx.gbl...
> Hi,
>
> I have a problem allocating memory in a c++ application for a 125MB xml
> string that I retrieved first out of a MSXML2::IXMLDOMDocument or
> MSXML2::IMXWriter (using msxml4 and msxml6).
>
> Note that this is probably not a msxml-specific problem since the error
> doesn't necessarily occur in msxml6; (besides I posted a message to the
> xml newsgroup some weeks ago).
> The problem rather depends on the size of the memory to be allocated.
>
> All memory allocation functions return or throw an error:
>
> - SysAlloc(): There is not enough storage to complete this operation
> - new wchar_t: throws bad_alloc
> - HeapAlloc(): throws error 17 - Not enough quota
>
>
> I don't know much about virtual, paged and nonpaged memory and that
> stuff, but I guess that it has to do something with this.
>
> Even the Task Manager is probably not a reliable source, it reveals that
> my 1GB of RAM is far from being consumed at the point of error.
> If I allocate 1GB of RAM in a test program by allocating several times
> 125MB then this test program doesn't throw an error.
>
>
> Does anybody have an idea what's going on and how I can solve this
> problem?
> Thanks for any information!
>
> --
> Klaus Triendl


From: klaus triendl on
Skywing [MVP] schrieb:
> I would suspect that you are seeing address space fragmentation. Can you
> try giving the output of `!address' from WinDbg on your program when the
> allocations are failing?

Your suspection might be correct.
I was using HeapReAlloc to allocate enough memory for the xml string copy.
Now, I've tried to use the xml string directly - i.e. just one copy out
of msxml6 - and it works better.

The problem still remains, though - the error just happens at a later
point. As I'm dealing with an application server - client model it could
practically be at any time.


Now, how do I get `!address' from WinDbg to work?
I've tried to play around a bit, but it says: "Your debugger is not
using the correct symbols; ReadField(StackLimit) error at 7ffdf000".

Is there a way to get the same information from the visual studio debugger?


> BTW, in my experience, for extremely large allocations it tends to be better
> to go directly to the VirtualAlloc APIs and not the heap manager APIs.

As I'm dealing with msxml I can't influence what memory allocation
function to use.
The memory allocation error doesn't necessarily happen in my code but
can already occur in msxml.


Any other way to solve the problem?



Thanks,
Klaus
From: Skywing [MVP] on
Make sure you have your symbol path set correctly. For instance, to use the
Microsoft public symbol server and download symbols to `c:\symbols' you
would use the command:

`.symfix c:\symbols'

or:

`.sympath srv*c:\symbols*http://msdl.microsoft.com/download/symbols'

(the `.symfix' command is a shorthand for the above `.sympath' command that
sets you to use the Microsoft public symbol server.)

Then, you can use `.reload' to ensure that symbols are recognized by the
debugger.

As for getting that from the VS debugger - not sure. I don't use the VS
debugger much nowadays.

--
Ken Johnson (Skywing)
Windows SDK MVP

"klaus triendl" <triendl.kj(a)m-box.at> wrote in message
news:44BF51AA.9080305(a)m-box.at...
> Skywing [MVP] schrieb:
>> I would suspect that you are seeing address space fragmentation. Can you
>> try giving the output of `!address' from WinDbg on your program when the
>> allocations are failing?
>
> Your suspection might be correct.
> I was using HeapReAlloc to allocate enough memory for the xml string copy.
> Now, I've tried to use the xml string directly - i.e. just one copy out
> of msxml6 - and it works better.
>
> The problem still remains, though - the error just happens at a later
> point. As I'm dealing with an application server - client model it could
> practically be at any time.
>
>
> Now, how do I get `!address' from WinDbg to work?
> I've tried to play around a bit, but it says: "Your debugger is not
> using the correct symbols; ReadField(StackLimit) error at 7ffdf000".
>
> Is there a way to get the same information from the visual studio
> debugger?
>
>
>> BTW, in my experience, for extremely large allocations it tends to be
>> better
>> to go directly to the VirtualAlloc APIs and not the heap manager APIs.
>
> As I'm dealing with msxml I can't influence what memory allocation
> function to use.
> The memory allocation error doesn't necessarily happen in my code but
> can already occur in msxml.
>
>
> Any other way to solve the problem?
>
>
>
> Thanks,
> Klaus


From: Hector Santos on
> > BTW, in my experience, for extremely large allocations it tends to be
better
> > to go directly to the VirtualAlloc APIs and not the heap manager APIs.
>
> As I'm dealing with msxml I can't influence what memory allocation
> function to use.
> The memory allocation error doesn't necessarily happen in my code but
> can already occur in msxml.
>
>
> Any other way to solve the problem?

Are you stuck using the MSXML parser? They are a dime a dozen on the net.

--
Hector Santos, Santronics Software, Inc.
http://www.santronics.com