code_junkie

Changing the reserve memory of C++ vector

Nov 12th, 2011
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. if(count + 1 > m_listItems.capacity())
  2. m_listItems.reserve(count + 100);
  3.  
  4. m_listItems.clear();
  5.  
  6. vector<Item>(m_listItems).swap(m_listItems);
  7.  
  8. vector<Item>().swap(m_listItems);
  9.  
  10. std::vector<foo> v(1000); // Create a vector with capacity for 1000 elements
  11.  
  12. std::vector< int > v;
  13. // ... fill v with stuff...
  14. std::vector< int >().swap( v );
  15.  
  16. vector< int > tmp;
  17. old.swap( tmp );
Add Comment
Please, Sign In to add comment