container inside container in stl

W

wolverine

Hi
Me being a beginner in c++ , i just want to know is their
anything special i have to take care when using container inside a
container.

eg:
vector inside a map which is inside a map

When i googled i found out people saying about memory leaking. Is this
true ?
I know about issues of holding pointer inside a vector and forgetting
to delete it. I am asking for any thing else. Thanks in advance

Regards
Kiran Pradeep
 
K

Kai-Uwe Bux

wolverine said:
Hi
Me being a beginner in c++ , i just want to know is their
anything special i have to take care when using container inside a
container.

eg:
vector inside a map which is inside a map

Nope: nothing special.
When i googled i found out people saying about memory leaking. Is this
true ?

I do not know of any implementation of the standard library that leaks
memory. However, it is popular to use pooling allocators so that memory
allocated for containers is kept around; e.g., deleting an element in a map
may not shrink the memory use of your program but that location of memory
will be used next time, when you insert an element.
I know about issues of holding pointer inside a vector and forgetting
to delete it. I am asking for any thing else.

Huh?


Best

Kai-Uwe Bux
 
M

Marcus Kwok

Kai-Uwe Bux said:

I think what the OP is saying is that he is aware of the memory leak
issue if you do something like:

std::vector<int*> vip;
vip.push_back(new int(3));

but then fail to do the equivalent of:

delete vip[0];

before the vector itself is destroyed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top