Skip to main content
gamedev.net
🔒 Locked

Extending an array

Started by jonbell May 14, 2003 at 1:12 PM 1 replies 200+ views
Original Post
jonbell
jonbell
if i do : int *i; i = new int [5]; how do i increase or shrink the array without having to start copying all the data into a new array and swapping pointers?
Dobbs
Dobbs
You can''t do it without copying and reallocation. The easiest solution would be to use the standard vector which handles all that dirty work for you.
Miserable
Miserable
Note: You can resize arrays created in the C-style way, with malloc or calloc, by using the function realloc. However, you should never mix calls to new/new[]/delete/delete[] with calls to malloc/calloc/realloc/free.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.