[Python-Dev] Re: Reiterability
Andrew Koenig
ark-mlist at att.net
Wed Oct 22 09:24:15 EDT 2003
> I thought we already established before that attempting to guess wihch
> parts of a generator function to copy and which parts to share is
> hopeless. generator-made iterators won't be __copy__-able, period.
> I think this is the weakness of this cloning business, because it
> either makes generators second-class iterators, or it makes cloning a
> precarious thing to attempt when generators are used. (You can make a
> non-cloneable iterator cloneable by wrapping it into something that
> buffers just those items that are still reacheable by clones, but this
> can still require arbitrary amounts of buffer space.
However, the buffering can be done in a way that uses only as much buffer
space as is truly needed. Just maintain the buffer as a singly linked list
in which new elements are inserted at the *tail* of the list. Then whenever
the head becomes unreachable (e.g. because no iterators refer to it), it
will be garbage collected.
More information about the Python-Dev
mailing list