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:
- red or black (1 boolean, 4 bytes due padding)
- parent (8 byte pointer)
- left child, right child (two 8 byte pointers)
- root object (8 byte pointer)
- data key (4 bytes int)
- 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
Post a Comment