Jump to content
  • Advertisement
Sign in to follow this  
DarkRonin

How to instantiate a 'new' STL vector?

This topic is 647 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

Hi guys,
 
How do you instantiate a 'new' for STL vectors?
 
I have a vector of int's but if I try to exceed 1330 instances the application throws memory exceptions. So I want to pre-allocate the space with 'new'.
 
int frames = 1330; // 1330 max without 'new'
std::vector<int>* anim = new std::vector<int> anim(frames);
 
This doesn't compile, but hopefully gives an indication of what I want to do.
 
Any help would be greatly appreciated.
 
Thanks in advance :)

Share this post


Link to post
Share on other sites
Advertisement

You want array of vectors....

 

int frames = 1330;
std::vector<int>* ivecs = new std::vector<int>[frames];

 

or just use a vector of vectors

 

typedef std::vector<int> intVector;

std::vector<intVector> anims(frames);

Share this post


Link to post
Share on other sites

You should never really need new/delete. As mentioned above, you can use a vector< vector<int> > if you want a 2D array. Any statement where new and vector are combined is an oxymoron.

Edited by sjhalayka

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!