buffered input (examples?)

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Feb 7 09:30:00 PST 2011


On 2/7/11 9:40 AM, Michel Fortin wrote:
> On 2011-02-07 08:24:32 -0500, spir <denis.spir at gmail.com> said:
>
>> Does this have anything to do with currently discussed buffered input
>> ranges? If yes, how does such a design, or any alternative, fit their
>> proposed interface?
>
> You can build all of this on top of a buffered input range. The buffered
> input range is not an alternative for your complex parsing algorithm,
> it's just the component managing the buffer.
>
> Having the underlying range manage the buffer (as opposed to having your
> parser algorithm doing it) means that the buffer implementation can vary
> depending on the type of range. For instance, if you're parsing directly
> data in memory, the buffered range can use directly this data in memory
> as the buffer, requiring no allocation and no copy; if you're parsing
> from a file or a network stream it'll use a more standard buffer.
>
> But how exactly the buffer is implemented does not affect your parsing
> algorithm in any way. That's the great thing about it, separation of
> concerns: your algorithm will work independently of the buffer
> implementation used. All your parser algorithm has to do is say
> "shiftFront" and "appendToFront" to control what's available in the buffer.

Very well put, thanks.

Andrei


More information about the Digitalmars-d mailing list