[Expat-discuss] Using XML_GetBuffer/XML_ParseBuffer

Karl Waclawek karl at waclawek.net
Sun Sep 24 06:38:07 CEST 2006


James Whetstone wrote:
> So I stepped through the code to see what happens to unused fragments, 
> and it leaves the fragments in the buffer.  From what I can tell, 
> instead of moving the offset of the input buffer, XML_GetBuffer is 
> intended to be called each time new input is to be accepted.
Yes.
> It then allocates a new (larger) buffer, memcpys the fragment from the 
> old buffer to the new buffer and then frees the old buffer.
No, only if the requested length plus the unprocessed fragment exceeds 
the size of the current buffer, otherwise
the unused fragment is simply moved to the beginning of the buffer.
> I'd like to avoid this by simple moving the input buffer's offset to 
> the a end of the fragment and NOT calling XML_GetBuffer to avoid the 
> extran memory allocation.  Any suggestions?
>
Your suggestion in your other message is good - requesting a larger 
buffer on the first call to XML_GetBuffer - should
reduce or eliminate new memory allocations.

Karl


More information about the Expat-discuss mailing list