List iterators.

EQ2Emulator Development forum.

Moderator: Team Members

Post Reply
bphillips
Posts: 1
Joined: Sun Oct 14, 2007 7:38 pm
Location: Texas

List iterators.

Post by bphillips » Mon Oct 15, 2007 6:50 pm

The code in the emulator has several loops like this:
for(iterator=clients.begin(); iterator!=clients.end(); iterator++){
}
If you change the iterator inside the loop, specifically, if you erase something from the loop, then reset the iterator to clients.begin() you will apply the ++iterator PRIOR to the conditional statment. If the list size has been changed to 0 this should throw an exception (maybe it doesnt with release compile on but it should...) at any length it is more stable to use one of the following options:
--two loops( easier and good for list that are expected to be short)
bool change = true;
while(change){
change=false;
for(i=list.beign; i!=list.end &&!change; i++){
if(){
//make erase
change=true;
}
}
}
--other option is to use a toRemove list
--bp

Bafoon
Posts: 73
Joined: Mon Jul 30, 2007 4:02 am
Location: Tampa,T&C FL

Post by Bafoon » Mon Oct 15, 2007 8:36 pm

Can someone explain this in human terms? I am always up for learning.

LethalEncounter
Team: Zombie
Posts: 2717
Joined: Wed Jul 25, 2007 10:10 pm

Post by LethalEncounter » Tue Oct 16, 2007 4:32 am

You are right but there are only a few locations in the code that dont exit the iterator if something was deleted from it. It will be fixed.

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests