Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

Efficient way of increasing array size by one element?

alexisgm
Beginner
383 Views
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
0 Kudos
1 Reply
TimP
Honored Contributor III
383 Views
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.
0 Kudos
Reply