Re: Array foreach in scripting languages
"Carsten Orthbandt" <[email protected]> Mon, 14 Aug 2006 07:50:21 +0200
| Newsgroups | gmane.games.devel.windows |
|---|---|
| Message-ID | <[email protected]> |
I tested this with both, my DynamicArray and std::vector. Since we're talking about a scripting language here, the actual implementation doesn't matter. It can be alinked list, contigous memory block, hashmap, whatever. Simply think of it as a resizeable array. As stated before, even the case where the current element gets removed from the list can be handled correctly because I can control the real lifetime of any object. So if the current element is removed in the foreach, there's still a reference to it from the iterator. Therefor it won't be freed immediately. Best regards, Carsten Orthbandt Founder + Development Director SEK SpieleEntwicklungsKombinat GmbH http://www.sek-ost.de Wenn ich Visionen habe, gehe ich zum Arzt. - Helmut Schmidt > -----Original Message----- > From: [email protected] > [mailto:[email protected]] > On Behalf Of Jon Watte > Sent: Sunday, August 13, 2006 10:05 PM > To: Game Development for MS Windows > Subject: Re: [GD-Windows] Array foreach in scripting languages > > What's confusing is that your code uses the name DynamicArray > (which I > suppose is close to ArrayList in .NET), and your C++ test sample > probably used std::vector, but you keep referring to the > container as a > "list". They are very different kinds of containers. > > You will note that C++ allows you to insert and delete objects in a > std::list, but not in a std::vector. The reason is that vectors are > guaranteed to be contiguous, and thus iterators (which may be simple > pointers) would get invalidated when resizing the underlying storage. > Meanwhile, when deleting from a list, the only iterator that gets > invalidated is an iterator pointing to the element being deleted. > > Cheers, > > / h+ > > > Carsten Orthbandt wrote: > > The obvious question is how should an active iterator react > if the traversed list > > changes? To answer this, I simply tried it out in two > languages I know that do > > provide both dynamic arrays and foreach: STL, Tcl and C#. > > > > > > -------------------------------------------------------------- > ----------- > Using Tomcat but need to do more? Need to support web > services, security? > Get stuff done quickly with pre-integrated technology to make > your job easier > Download IBM WebSphere Application Server v.1.0.1 based on > Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057& > dat=121642 > _______________________________________________ > Gamedevlists-windows mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=555 > ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Gamedevlists-windows mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows Archives: http://sourceforge.net/mailarchive/forum.php?forum_id=555