- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Is there an elegant way to increase an array size without losing its data, or resorting to temporary storage?
I have this array that can vary in length from ~10 elements to ~1000000 elements. I don't really know the upper limit on its size. Currently, when I need to increase its size to add extra data, I have to copy its contents to a temporary array, deallocate the first one, reallocate it with a bigger size, and recopy the data, along with the new data. I was thinking that there must be a better way to do this, but I really don't know how. Any help would be greatly appreciated,
Thanks!
Alexis
Is there an elegant way to increase an array size without losing its data, or resorting to temporary storage?
I have this array that can vary in length from ~10 elements to ~1000000 elements. I don't really know the upper limit on its size. Currently, when I need to increase its size to add extra data, I have to copy its contents to a temporary array, deallocate the first one, reallocate it with a bigger size, and recopy the data, along with the new data. I was thinking that there must be a better way to do this, but I really don't know how. Any help would be greatly appreciated,
Thanks!
Alexis
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With so many excellent discussions available at the touch of the forum search button, I won't attempt a complete answer. If you search a little further, you may conclude that the usual situation is to increase by a larger number of elements, to avoid excessive reallocation, and of course to arrange so that one copy of the data is sufficient rather than two.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page