container inside container in stl

Discussion in 'C++' started by wolverine, Jul 24, 2006.

  1. wolverine

    wolverine Guest

    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
     
    wolverine, Jul 24, 2006
    #1
    1. Advertising

  2. wolverine

    Kai-Uwe Bux Guest

    wolverine wrote:

    > 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
     
    Kai-Uwe Bux, Jul 24, 2006
    #2
    1. Advertising

  3. wolverine

    Marcus Kwok Guest

    Kai-Uwe Bux <> wrote:
    > wolverine wrote:
    >> I know about issues of holding pointer inside a vector and forgetting
    >> to delete it. I am asking for any thing else.

    >
    > Huh?


    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.

    --
    Marcus Kwok
    Replace 'invalid' with 'net' to reply
     
    Marcus Kwok, Jul 24, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Allan Bruce

    To STL or not to STL

    Allan Bruce, Oct 16, 2003, in forum: C++
    Replies:
    41
    Views:
    1,088
    Christopher Benson-Manica
    Oct 17, 2003
  2. Maitre Bart
    Replies:
    2
    Views:
    536
    Maitre Bart
    Feb 11, 2004
  3. Replies:
    4
    Views:
    815
    Daniel T.
    Feb 16, 2006
  4. Rares Vernica

    STL save reference inside container

    Rares Vernica, Feb 24, 2007, in forum: C++
    Replies:
    4
    Views:
    395
    John Harrison
    Feb 24, 2007
  5. none
    Replies:
    8
    Views:
    409
Loading...

Share This Page