Thread: Unordered map behavior on clear and reserve

  1. #16
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Why does something like this give me 50 allocations?
    O_o

    I would assume you are seeing the allocations you find problematic because nodes are being created for each bucket.

    The exception guarantees of various containers imply certain implementation characteristics. The easiest way to conform to these requirements is to use operations which can't, by definition, raise any exception. Operations on raw pointers--like `std::swap(raw_pointer1, raw_pointer2)' for example--are some of the few operations which can't raise an exception.

    The implementation is probably allocating a new scratch node instead of trying to make multiple updates to a complex object infallible.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  2. #17
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by MutantJohn View Post
    I know I should get off the net because it's New Year's Eve but...
    Now why would you want to do that? The net is where all the action happens. Just because it's new year's eve... pfft. Your IRL friends and family can wait!

    On a more serious note... just look at the STL code. Step through it if you must.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. implementing with map, and unordered map
    By jaesungj in forum C++ Programming
    Replies: 0
    Last Post: 11-08-2013, 09:45 AM
  2. Replies: 5
    Last Post: 06-30-2011, 10:29 PM
  3. capacity and reserve
    By George2 in forum C++ Programming
    Replies: 33
    Last Post: 03-06-2008, 08:14 PM
  4. Reserve the character in a string
    By alice in forum C Programming
    Replies: 2
    Last Post: 06-13-2004, 07:59 AM