|
From: Ioannis V. <iv...@em...> - 2003-07-14 21:18:49
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Shane Bryldt
> Sent: Monday, July 14, 2003 11:04 PM
> To: Jaap de Wolff
> Cc: C++
> Subject: Re: [Dev-C++] STL Map question
>
>
> After speaking with a few people, it appears to me that the
> problem is not
> at all with STL, at least not the fault of STL, but rather of original
> implementation.
[...]
It appears that you are an OK C programmer but missing the key concepts of
C++. I suggest you read "The C++ Programming Language" 3rd Edition or
Special Edition by Bjarne Stroustrup (the creator of C++), cover to cover.
It will take years, it will have pain but that's how knowledge is aquired.
> A last note, just to get a couple opinions. The original
> code that worked,
> would delete users as they were disconnected. The newer code,
> using the same
> concept for UserList, crashes. What I have done (but not yet
> tested) is
> changed the code where it delete's the User, instead of
> deleting them, it
> sets a flag indicating they are ready to be processed for
> deletion. At the
> top of every loop iteration, it generates a vector of Killed
> connections,
> then steps through the vector and deletes them from the user
> list map. The
> change in implementation of how the User is deleted may lend itself to
> fixing the problem in certain very strange conditions. Does
> anyone see a
> flaw with how I changed the code? I haven't tested it yet, beyond a
> controlled environment where the crash wouldn't occur
> anyways
Flags? See what I wrote above.
>. I'm hoping
> with little hope that it may simply be a matter of iterator
> invalidation,
> and by not deleting the User and removing it right away, it
> might (??? I'm
> really running out of ideas) fix the problem.
I have already told you what to do. Use the containers with *objects*, not
pointers.
E.g. map<string, User>Users;
map<string, User>::iterator p=Users.find("Zefxes");
if(p!=Users.end())
{
// ...
// Zefxes is erased
Users,erase(p));
// Users["Zefxes"] now returns User(0)
// Users.find("Zefxes") now returns Users.end()
}
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|