std containers and memory

Discussion in 'C++' started by Dylan, May 18, 2005.

  1. Dylan

    Dylan Guest

    If I reserve some memory for a std container, let's say

    std::vector<int> myInts;
    myInts.reserve(100);

    and then allocate another std:vector to it, like so:

    std::vector<int> myOtherInts(30, 10);

    myInts = myOtherInts;

    Is myInts using the reserved memory or allocating a new block?

    thanks
     
    Dylan, May 18, 2005
    #1
    1. Advertising

  2. Dylan wrote:
    > If I reserve some memory for a std container, let's say
    >
    > std::vector<int> myInts;
    > myInts.reserve(100);
    >
    > and then allocate another std:vector to it, like so:
    >
    > std::vector<int> myOtherInts(30, 10);
    >
    > myInts = myOtherInts;
    >
    > Is myInts using the reserved memory or allocating a new block?


    That's probably implementation specific. I don't believe the standard
    mandates any particular behaviour.
     
    Gianni Mariani, May 18, 2005
    #2
    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. Anton
    Replies:
    1
    Views:
    369
    Peter van Merkerk
    Aug 6, 2003
  2. Peter Jansson
    Replies:
    5
    Views:
    6,318
    Ivan Vecerina
    Mar 17, 2005
  3. Vinu
    Replies:
    4
    Views:
    362
    Jim Langston
    Jul 7, 2005
  4. Replies:
    7
    Views:
    555
    Pete Becker
    Jan 25, 2008
  5. Sebastian Mach
    Replies:
    5
    Views:
    315
Loading...

Share This Page