Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

krez

inner workings of STL vectors

This topic is 5853 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how exactly does an STL vector store the objects you push_back into it? i have done this in two ways:
    
// CPolygon is my own homemade class

// p_vector is a member variable of the class all this is in

void TestVector(void)
  {
  CPolygon tPOLY[10];
  for (int i = 0; i < 10; ++i)
    {
    tPOLY[i].initCrap();
    p_vector.push_back(tPOLY[i]);
    };
  };

void TestVector2(void)
  {
  CPolygon * tPOLY = new CPolygon[10];
  for (int i = 0; i < 10; ++i)
    {
    tPOLY[i].initCrap();
    p_vector.push_back(tPOLY[i]);
    };
  };
    
when the first one worked, i assumed that STL vector must copy the stuff you put in it, since the array of CPolygons i created would go out of scope and be destroyed right after they are put in the vector. i also discovered that when using the array allocated in the heap, i could delete[] them before the function returns, and the vector still contains usable data. so, this post is just to affirm my thoughts, because i don't want things to fall apart later because of faulty assumptions. does the STL vector in fact copy the objects you push_back() into it? or am i just "getting lucky" with this example? thanks! EDIT: duh... i forgot the other part of my question: does the "clear" function in the vectors clean up the objects inside it? meaning, does it call their destructors? --- krez (krezisback@aol.com) [edited by - krez on September 15, 2002 5:26:04 PM]

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!