I have declared a map object with (int, string). The string size is 128 bytes. However, a new Map nodes size remains constant 48 bytes. I have checked this with custom allocation.
std::map<int, std::string, std::less<int>, my_allocator< std::pair<const int, std::string> > > custom_map;
gen_random(random_string, 103); //generates a random string of size 103 and stored in random_string
custom_map.emplace(i, std::string(random_string)); //allocates 48 bytes for map
/* the string is allocated separately */
My question is - what does the map node hold? (I am assuming based on the behavior of the above code, some metadata for the red-black tree, the key, and a pointer to the value are held in the map node.)
Motivation:
I have a kernel module that manages persistent memory. It makes persistent memory accessible to applications by mapping them to applications address space. It also has support atomic msync.
I am trying to develop a simple persistent key value store using c++ STL map. So, I tried to create a custom allocator to allocate the stl::map objects from the persistent memory. I have a memory pool mapped from the persistent memory device, which is used by the custom allocator. So I need to make sure, everything related to the MAP (key, value, internal nodes) are allocated from that pool.
When I saw the Map object/node size is less than the (int, string) pair size, I got confused as I assumed everything(key+value) will be contained inside the map node that is allocated using the custom allocator. However, that is not the case. So I need to know about the MAP nodes setup to guarantee everything (Not more or less) related to the Map object is allocated from the persistent memory pool.
I hope it clears the motivation. Any suggestion is highly appreciated.