|
Boost : |
From: Bruno MartÃnez Aguerre (br1_at_[hidden])
Date: 2005-01-17 07:34:58
Coroutines or threads are overkill for this problem, IMHO. What you need
is laziness, as in haskell. FC++ probably can handle decompress with less
overhead than threads.
Bruno Martinez
On Thu, 13 Jan 2005 16:12:44 -0700, Jonathan Turkanis
<technews_at_[hidden]> wrote:
> If we want to preserve the simplcity of the example without requiring
> that an
> enitre stream of data be processed at once, we could switch to
> thread-aware
> concepts. E.g.,
>
> template<typename AsyncSource, typename AsynSink>
> void decompress(AsyncSource& in, AsynSink& out)
> {
> char c;
> while((c = boost::io::blocking_get(in)) != EOF) {
> if(c == 0xFF) {
> int len = boost::io::blocking_get(in);
> if(!in || !boost::io::blocking_get(in)) // Return an error.
> while(len--) boost::io::blocking_put(out, c);
> }
> else {
> boost::io::blocking_put(out, c);
> }
> }
> }
>
> (I've been planning to introduce such concepts eventually, but
> definitely not in
> the initial release.)
>
> With some sacrifice of efficiency, we could even use your example
> unchanged, and
> stipulate that the provided istream and ostream wait on some
> synchronization
> object until input is available or EOF is reached (for the istream) or
> until the
> output buffers have free space (for the ostream).
>
> In short, I 'm not sure the co_filter idea can be implemented without
> some cost
> in efficiency or simplicity.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk