Re: allocatable array *not* equivalent to dynamic allocation?
- From: "David Frank" <dave_frank@xxxxxxxxxxx>
- Date: Wed, 31 May 2006 07:18:51 -0400
"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
.
- Follow-Ups:
- Re: allocatable array *not* equivalent to dynamic allocation?
- From: Craig Powers
- Re: allocatable array *not* equivalent to dynamic allocation?
- References:
- allocatable array *not* equivalent to dynamic allocation?
- From: Lo
- Re: allocatable array *not* equivalent to dynamic allocation?
- From: Brooks Moses
- Re: allocatable array *not* equivalent to dynamic allocation?
- From: Craig Powers
- Re: allocatable array *not* equivalent to dynamic allocation?
- From: glen herrmannsfeldt
- allocatable array *not* equivalent to dynamic allocation?
- Prev by Date: true 64-bit FORTRAN compilers for Windows XP 64??
- Next by Date: Re: Fortranspeak & Javaspeak
- Previous by thread: Re: allocatable array *not* equivalent to dynamic allocation?
- Next by thread: Re: allocatable array *not* equivalent to dynamic allocation?
- Index(es):
Relevant Pages
|