# Thread: Can someone explain this concept to me

1. ## Can someone explain this concept to me

I am currently learning how to use maps and i find a few things confusing
e.g if i have
Code:
`map<string ,vector<string > value;`
1.whats the original size of the map when i declare it
2.does each string inserted have a pointer/mapping to a string vector?

2. Originally Posted by sigur47
I am currently learning how to use maps and i find a few things confusing
e.g if i have
Code:
`map<string ,vector<string > value;`
1.whats the original size of the map when i declare it
2.does each string inserted have a pointer/mapping to a string vector?
1. Some memory is allocated for it (on the heap.. afaik), but you needn't worry about it, as it expands on demand.
If you ever need to control that behaviour, the map container takes two more template parameters, look into what the fourth (allocator) does.

2. Maybe, internally or may not be. Totally depends on the implementation. (btw.. what do you mean by 'mapping' ?)

3. 1. The original size (in the sense of calling size() on it) is 0.

2. Each inserted string key will have its own vector<string> associated with it, not just a pointer.

Code:
```#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

int main() {
map<string, vector<string> > m;
cout << m.size() << endl; // Zero size.

// Create a vector with two elements.
vector<string> v;
v.push_back("abc");
v.push_back("def");

m["x"] = v; // Each of elements "x" and "y"
m["y"] = v; // have their own copy of v.
cout << m.size() << endl;

m["y"][0] = "ghi"; // Only changes map element "y"s copy of v.

cout << m["x"][0] << endl;
cout << m["y"][0] << endl;

m["a"]; // Just mentioning a non-existent element
// creates a new vector.
cout << m.size() << endl;

m["a"].push_back("xyz");
}```

4. Originally Posted by sigur47
1.whats the original size of the map when i declare it
Call its size() method straight after the declaration and it'll tell you how many items it contains at that time. (It's zero by the way)

2.does each string inserted have a pointer/mapping to a string vector?
Every map contains two types of things; things of the first type that map to things of the second type. You can look up something of type A and will find along with it a thing of type B. The two types can of course be the same. This map will contain strings that map to vectors of strings.

5. Many of the things you ask are totally irrelevant. This depends on a typical implementation.
A better question to ask is: is X guaranteed to work, instead of to get X to work, I probably need Y and Z, so does <container> fulfill Y and Z?