Re: [GD-Windows] Array foreach in scripting languages
Brought to you by:
vexxed72
From: Carsten O. <car...@se...> - 2006-08-14 05:50:07
|
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 =20 > -----Original Message----- > From: gam...@li...=20 > [mailto:gam...@li...]=20 > 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 >=20 > What's confusing is that your code uses the name DynamicArray=20 > (which I=20 > suppose is close to ArrayList in .NET), and your C++ test sample=20 > probably used std::vector, but you keep referring to the=20 > container as a=20 > "list". They are very different kinds of containers. >=20 > You will note that C++ allows you to insert and delete objects in a=20 > std::list, but not in a std::vector. The reason is that vectors are=20 > guaranteed to be contiguous, and thus iterators (which may be simple=20 > pointers) would get invalidated when resizing the underlying storage.=20 > Meanwhile, when deleting from a list, the only iterator that gets=20 > invalidated is an iterator pointing to the element being deleted. >=20 > Cheers, >=20 > / h+ >=20 >=20 > Carsten Orthbandt wrote: > > The obvious question is how should an active iterator react=20 > if the traversed list > > changes? To answer this, I simply tried it out in two=20 > languages I know that do > > provide both dynamic arrays and foreach: STL, Tcl and C#. > > =20 >=20 >=20 >=20 > -------------------------------------------------------------- > ----------- > Using Tomcat but need to do more? Need to support web=20 > services, security? > Get stuff done quickly with pre-integrated technology to make=20 > your job easier > Download IBM WebSphere Application Server v.1.0.1 based on=20 > Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057& > dat=3D121642 > _______________________________________________ > Gamedevlists-windows mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_id=3D555 >=20 |