[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
On Tue, 12 Aug 2003, James McCartney wrote:
> There are so many drawbacks to that technique that I don't think it is
> very useful in any practical situation. Doesn't deal with allocations
> and deallocations very well. Can't yield from the coroutine from a
> function called by the function. etc.
It's very useful for at least one practical situation: writing tokenizers.
I've been rewriting two of the tokenizers in the code I write at work, and
the technique has come in handy.
I don't understand why you think it doesn't deal well with memory
management -- it deals as well as any C/C++ code does.
As for yielding from subfunctions, you simply need to reapply the
technique to every function you call -- after all, they're coroutines
themselves. If you're dealing with highly-recursive but semantically
simple data structures like trees, then the overhead may not be worth it.
But if you're dealing with mostly-linear and semantically complex data
structures like byte streams, then it can be very useful.