Re: allocatable array *not* equivalent to dynamic allocation?
- From: Craig Powers <enigma@xxxxxxxxxx>
- Date: Wed, 31 May 2006 11:21:27 -0400
David Frank wrote:
"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
And I would imagine (without actually looking at the nearest-to-hand implementation) that std::vector does close to the same thing.
.
- 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
- Re: allocatable array *not* equivalent to dynamic allocation?
- From: David Frank
- allocatable array *not* equivalent to dynamic allocation?
- Prev by Date: Re: Algorithm help for unique string searching/counting within an array.
- Next by Date: Re: Bounds Check Overhead
- 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
|