nietras
nietras

Reputation: 4048

Unbuffered XmlReader implementation

does anyone know of an unbuffered XmlReader implementation?

Not the XmlTextReaderImpl which uses a byte[] buffer internally and reads from a stream at construction! I find this incredibly annoying. I only want the XmlReader to read when actually calling Read* on the object. Not to buffer data or similar.

NOTE: I am not talking about cached vs non-cached. But stream buffering, which happens internally in the XmlTextReader for example.

I want to use this in a scenario where I currently have to create a new XmlTextReader each time I want to deserialize an object, but since this creates a buffer of size 4096 every time it puts a lot of pressure on the garbage collector. So I would like to keep an instance of the XmlReader around (which can continously read from a stream of xml objects), but this is not possible with the BCL implementation or have an XmlReader that does not create a buffer.

Upvotes: 2

Views: 838

Answers (1)

sehe
sehe

Reputation: 393507

Not creating a buffer coule be impossible.

The parser needs to have lookahead, not to mention NameTables for fast processing.

4096 seems big, but might be the most efficient unit: it coincides with a page of virtual memory, and it could be used in stead of many repeated small allocations (? guessing)

However, reusing the instance would have been nice. You could have a look at the mono implementation and work it to your liking:

https://github.com/mono/mono/blob/master/mcs/class/System.XML/System.Xml/XmlTextReader.cs

Upvotes: 1

Related Questions