c++ - Explosion of memory using std::map -


i have problem using std::map in c++ vs10. when run simple code

std::map<int,int>mymap; for(size_t i=0;i<1000000;i++){      mymap[i]=i; } 

my memory explodes 256mo seems strange me. , if use

std::vector<int>myvector(1000000); 

i obtain 4mo predicted.

if can explain phenomena.

std::map implemented red-black tree means following fields, assuming x64:

  1. red or black (1 boolean, 4 bytes due padding)
  2. parent (8 byte pointer)
  3. left child, right child (two 8 byte pointers)
  4. root object (8 byte pointer)
  5. data key (4 bytes int)
  6. data value (4 bytes int)

this gets 44 bytes per item or 44 megabytes of memory. unlike in std::vector case each of these independently object adds 24 bytes of additional data. brings 68 megabytes. still quarter of seeing @ least can see why there huge difference in sizes.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -