[Mono-list] IEnumerators

Jason Diamond jason@injektilo.org
Tue, 17 Jul 2001 01:12:53 -0700


This article suggests the same approach and actually claims that this is how
Microsoft does it:

http://codeguru.com/cs_collections/enumeration.html

Personally, the chance for one error for every 4 billion modifications seems
acceptable to me.

Jason.

> -----Original Message-----
> From: mono-list-admin@ximian.com [mailto:mono-list-admin@ximian.com]On
> Behalf Of David Menestrina
> Sent: Tuesday, July 17, 2001 12:52 AM
> To: mono-list@ximian.com
> Subject: [Mono-list] IEnumerators
>
>
> IEnumerator.MoveNext() has to throw
> InvalidOperationException if the object it's
> enumerating is modified in any way.  I tested this
> with MS's implementation of BitArray, and it seems to
> really detect *any* change to the original object.
>
> Maybe my brain is fried, but I can't seem to think
> of a great way to implement this.  The best way I can
> think of is to have the original object keep a change
> count.  Whenever any call modifies the object,
> increment the count.  The IEnumerator will store
> the value on creation, then check it every time you
> call MoveNext().
>
> This works in all cases except when you modify
> something 4 billion times before calling MoveNext.
>
> Does anyone have a cleaner idea?  I can't keep
> pointers
> to all the IEnumerators, because then they'd never
> get GC'ed.
>
> Thanks,
> david
>
> __________________________________________________
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/
>
> _______________________________________________
> Mono-list maillist  -  Mono-list@ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>