Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.fortran    |    Putting John Backus on a giant pedestal    |    5,127 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 4,528 of 5,127    |
|    gah4 to GianLuigi Piacentini    |
|    Re: A question on reallocation    |
|    15 Nov 23 20:19:01    |
      From: gah@ugcs.caltech.edu              On 11/15/23 10:40 AM, GianLuigi Piacentini wrote:       > Hi all,       >       > I have a perhaps silly question, that puzzles me before committing to       > write actual code.       >       > Please consider a data structure which is basically an array of arrays       > type element       > integer, allocatable :: element_core(:)       > end type       > ...       > type(elements), allocatable :: array_of_elements(:)       > ...       > allocate ( array_of_elements(some_size) )              (snip)              > type(elements), allocatable :: tmp(:)              > allocate ( tmp(new_size) )       > tmp(1:some_size) = array_of_elements !       ***       > call move_alloc(from = tmp, to = array_of_elements)                     I think you want something like:              allocate(tmp(new_size))              do i=1, old_size        call move_alloc(from=array_of_elements(i), to=tmp(i))       end do              call move_alloc(from = tmp, to = array_of_elements)              So, move all the subarrays over, then move the array of arrays.              Since only the, fairly small, array_of_elements is being reallocated,       it should be pretty fast.              Before move_alloc, you had to create a temporary, copy them over,       reallocate the original one, and copy them back. Lots of copying!              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca