A comment in CProcessManager::UpdateProcesses that I would have appreciated

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • A comment in CProcessManager::UpdateProcesses that I would have appreciated

      I know a bit of basic C++ so I'm writing my own stuff while reading the book, instead of copying Mike's soures exactly. However I had never used STL before so I managed to program in a bug that took me an hour to figure out. Probably sounds kinda stupid if you're used to STL and stuff.. But I'd think it would be nice if the following comment was inserted like this:

      Source Code

      1. while ( i != m_ProcessList.end() )
      2. {
      3. // Increase the iterator before we proceed, since the current object might be removed from the list
      4. shared_ptr<CProcess> p = shared_ptr<CProcess>(*i);
      5. ++i;


      (line 183 in CProcess.cpp, code 2.3, and page 177 in the book)
    • RE: A comment in CProcessManager::UpdateProcesses that I would have appreciated

      You're right - iterating though dynamic lists can be tricky...
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • So, you flag for deletion and remove them in a separate seciton of the update() funcition? Or you call a "CleanUp()" somewhere?

      I think I would clean out flagged Processes at the beginning of the update(), update the remaining active processes and then add new Processes after that so that they could commence on the next update() pass. I'm just thinking out loud though....
      "Your job is not to die for your country. Your job is to make some other poor sod die for his."
    • I believe he's talking about the delayed deletion. I delay all of my removes by a frame, in the ProcessManager implementation that I wrote, the EventManager implementation that I wrote, the entity system we're using, etc etc.
      Feel you safe and secure in the protection of your pants . . . but one day, one day there shall be a No Pants Day and that shall be the harbinger of your undoing . . .
    • That's what the CProcessManager does - it's what the m_bKilled flag is for....
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • It's been a while since I looked at it - and I suppose that's where I got that train of thought from.... :D

      Note that, in the system as implemented by Mike the "killed" processes are removed from the list before the list is fired and the "to be killed" processes are flagged as they are fired so that they will be deleted on the next pass. Effectively, the deletion is delayed a frame and it is done immediately prior to firing the list so that dead prosesses are not fired.

      Note also that "fire" and the verb "process" are synonyms in the preceeding and was used to avoid sounding like a complete jerk....

      "The processes are deleted before the remaining processes are processed and then ...." :tongue:
      "Your job is not to die for your country. Your job is to make some other poor sod die for his."

      The post was edited 1 time, last by Nebuchadnezzar ().