Thread: Why isn't map::find() finding anything?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by cpjust View Post
    I just thought of that when I got home.
    It's unlikely that a UserID would be pushed onto the vector and not removed by the other thread, but with this spagetti code anything is possible, so using a std::set would at least minimize a possible memory leak to a much smaller size.
    If you're using std::string/std::wstring contained in a std::map/std::set, there shouldn't be any leaking, unless you're doing something really wrong. The nice thing about std::string, set, map, etc. is that they help reduce the coded needed to avoid leaking. My main motive for suggesting std::set is that finding userIDs would be O(log(n)) instead of O(n)

    Be sure that access to the container and its contents is thread-safe, of course.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by Cactus_Hugger View Post
    If you're using std::string/std::wstring contained in a std::map/std::set, there shouldn't be any leaking, unless you're doing something really wrong. The nice thing about std::string, set, map, etc. is that they help reduce the coded needed to avoid leaking. My main motive for suggesting std::set is that finding userIDs would be O(log(n)) instead of O(n)

    Be sure that access to the container and its contents is thread-safe, of course.
    Oh thanks, that's another good reason to use a std::set that I didn't think of.
    The "memory leak" I was talking about is that I have 1 function adding users to the vector and another taking them off the vector. If something goes wrong and the 2nd function doesn't get called and therefore never removes the users from the vector, it would keep getting bigger and bigger. Also, since vectors allow duplicate entries, it grows indefinitely, whereas a std::set doesn't allow duplicates, so even if the users aren't removed, there wouldn't be that many users in the company to cause a huge memory leak. But that's just a cover my ass scenario, since I can't see a reason why the 2nd function wouldn't get called.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tools for finding memory leaks
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2009, 11:41 AM
  2. Finding primes
    By starripper in forum C++ Programming
    Replies: 19
    Last Post: 01-14-2006, 04:17 PM
  3. ROW OPERATIONS (finding Inverse) (im going crazy)
    By alexpos in forum C Programming
    Replies: 1
    Last Post: 11-20-2005, 10:07 AM
  4. MFC :: Finding Child Window of a CWnd* Object?
    By SyntaxBubble in forum Windows Programming
    Replies: 2
    Last Post: 09-06-2003, 09:06 AM
  5. Finding the algorithm that's right for you.
    By sean in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 02-03-2002, 10:03 AM