[Expat-discuss] Question with memory

Karl Waclawek karl at waclawek.net
Wed Apr 16 14:14:42 EDT 2003


>   I have just started using Expat XML parser and got a question with it. I have 
> a file of the order of 50Mb, and I wanted to parse it. I ran a loop reading each
>  line to a buffer I got from calling XML_GetBuffer(),

You should not really process line by line, since that may
alter the document if you consume the line breaks.
Just read the file buffer by buffer (in whatever buffer size you like)
and pass that to Expat. Check the demo apps in the Expat distribution.

> but I have a concern here,
>  does Expat free the space once it encounters the end tag? When i went through 
> the code I got a impression that the freeing is done only after the entire 
> document is parsed, but I am not sure of it. 

Don't free a buffer allocated by Expat. Expat will take care of it.

>   I wrote a simple test module where I printed out the address which 
> XML_GetBuffer() function returns and it looks to me that memeory is not reused. 
> Can some one clarify about it. Thanks -Praveen

That is internal to Expat - sometimes Expat will re-allocate
internally due to unused input at the end of the previous buffer.
Again, check the demo apps and follow their example.

Karl



More information about the Expat-discuss mailing list