is there an equivilent to C's realloc? i think i may want to experiment with it and see if i can make a dynamically sized random access array, but i also think it might get fragmented, so arrays no longer work. anyways, is there?
is there an equivilent to C's realloc? i think i may want to experiment with it and see if i can make a dynamically sized random access array, but i also think it might get fragmented, so arrays no longer work. anyways, is there?
No...C++ doesnt give a conversion of realloc.....
oh well, now that i think about it things could get realllly screwed up. if you allocated an array 'x' with 10 elements and then array 'y' took up the space afterwords, and then reallocated x for 20 elements, it might not be continuous so it can't be used like a continuous array. oh well, worth a shot i guess
>it might not be continuous so it can't be used like a continuous array.
Actually, if the new size can't be allocated with the current block, realloc is free to allocate a new block that is large enough, but in a different location. This is why any existing pointers to data inside of that block can be invalidated after a call to realloc.
In C++ you can fake realloc by allocating a new block with the new size and copying the elements to that new block, then delete the old block and reassign the pointer.
-Prelude
My best code is written with the delete key.
realloc, meet the vector.