CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863
    I did forget one thing. One the m_PendingJobs map becomes empty I have to make sure to empty the m_JobKeys deque

    The proper code at the completion of a job is
    PHP Code:
    if (wParam != m_PendingJobs.size() - 1)
        
    m_JobKeys.push_back(wParam);
    m_PendingJobs.erase(m_PendingJobs.find(wParam));
    if (
    m_PendingJobs.empty())
        
    m_JobKeys.clear(); 
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  2. #17
    Join Date
    Dec 2003
    Location
    Slovenia
    Posts
    4

    Post Re: std::map key values

    Originally posted by souldog

    I need to generate new unique key values. I could just find the largest key with a reverse iterator and add one. A remote, but conceivable problem is that the key values keep growing until they are too large for int. Since I ecpect elements of the map to be removed at a pretty good rate, I decided to find the first available key value...
    1. If you use unsigned int as key and i is the MAX value of unsigned int, then i++ is 0

    2. When you remove a job, delete the greatest key and insert its job at the key of deleted job. for new jobs, you could then use greatest key + 1 (but if you use all the keys possible (4, 000, 000, 000 + something I think), you would still have a problem)

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured