Re: allocatable array *not* equivalent to dynamic allocation?




"glen herrmannsfeldt" <gah@xxxxxxxxxxxxxxxx> wrote in message
news:zsqdnf5YN8ah2uDZnZ2dnUVZ_vSdnZ2d@xxxxxxxxxxxxxx
Craig Powers wrote:

(snip regarding reallocation)

As I understand it (not having looked at it lately), even the "normal"
dynamic memory access of the C++ (1998) standard library uses this form
of extending something. It's just that it gets buried under the hood of
the standard templates, something that isn't so easy to do in F95.

With C, and I believe also C++, it can be done with at most one copy.
As I understand it, to do it in standard Fortran 90 or 95 requires two
copies. Copy to a temporary array, deallocate and allocate a larger
version of the original array, copy the data back, deallocate the
temporary array.

-- glen


program one_copy_reallocate_x
real,pointer :: x(:)
real,allocatable,target :: y(:)
real :: z(91:100) = [91:100]

allocate ( x(90) ) ; x = [1:90]
allocate ( y(size(x)+size(z))) ; y = [x,z] ! 1 copy
x => y
write (*,*) size(x), x(89:91) ! 100 89. 90. 91.
end program


.



Relevant Pages

  • Re: Modifying subroutine or function arguments
    ... < end program test ... Still not required by the standard. ... likely require a temporary array. ... it wasn't added earlier in Fortran, ...
    (comp.lang.fortran)
  • Re: allocatable array *not* equivalent to dynamic allocation?
    ... dynamic memory access of the C++ standard library uses this form of extending something. ... It's just that it gets buried under the hood of the standard templates, something that isn't so easy to do in F95. ... Copy to a temporary array, deallocate and allocate a larger version of the original array, copy the data back, deallocate the temporary array. ...
    (comp.lang.fortran)
  • Re: allocatable array *not* equivalent to dynamic allocation?
    ... dynamic memory access of the C++ standard library uses this form of extending something. ... It's just that it gets buried under the hood of the standard templates, something that isn't so easy to do in F95. ... Copy to a temporary array, deallocate and allocate a larger version of the original array, copy the data back, deallocate the temporary array. ...
    (comp.lang.fortran)
  • Re: Giuen Holding Ltd. Outright; HUMMER H2 Vehicle Overview
    ... Styling cues like giant tires and side latches on the hood of the H2 ... standard 17-inch wheels are positioned at the extreme corners, ... suspension is available.The Glacier Blue limited edition features body- ... the H2 SUV when it's equipped with the optional folding/removable one- ...
    (talk.politics.mideast)
  • Re: Reassociation of pointers
    ... found it (though I don't have a fresh copy of the standard): ... 20 If a pointer appears in a DEALLOCATE statement, ...
    (comp.lang.fortran)