From: Frank Birbacher on
Hi!

shuisheng schrieb:
> The element of the map: pair<int, double>(0, 3.14) is in heap or
> stack? I think to know it is important for memory management.

It does not matter to the user of the map. The map does the memory
management internally and stores copies of all elements.

It will be allocated on the heap. Memory management can be changed by
supplying a different allocator. But writing allocators is not
documented well and requires some expertise.

Frank

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: robin on
On Dec 9, 9:49 am, shuisheng <shuishen...(a)yahoo.com> wrote:
> Dear All,
>
> I am wondering the inserted element in std::map is located in heap or
> stack? For example
>
> std::map<int, double> a;
> a[0] = 3.14;
>
> The element of the map: pair<int, double>(0, 3.14) is in heap or
> stack? I think to know it is important for memory management.

I think you can trace into the "[]" operator of the map and see where
it allocates the memory on when "a[0] = 3.14" is executed.

As to the map implementation I'm using, it allocates the storage on
the heap.

Regards


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]