Jump to content
  • Advertisement

Archived

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

delbogun

change size of an array

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

If i have a array myArray[5], is it possible to change the size of the array to newArray[10]? I know it''s possible in Java (myArray = newArray)

Share this post


Link to post
Share on other sites
Advertisement
You can''t do that with built in arrays.
In C++, check out the std::vector class.
In C, look into dynamic allocation using malloc, realloc, free. realloc is a bit dodgy because it can move data about.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Share this post


Link to post
Share on other sites
You have to do (for int):

  
int myArray[5];
int newArray[10];

memcpy(newArray, myArray, 5 * sizeof(int));

// if you allocated myArray with new then you can delete it now




schiggl

Share this post


Link to post
Share on other sites

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