Re: allocatable array *not* equivalent to dynamic allocation?
- From: Craig Powers <enigma@xxxxxxxxxx>
- Date: Tue, 30 May 2006 18:28:58 -0400
Brooks Moses wrote:
As James said in his reply, this is talking about the fact that, with Fortran allocatable arrays, you cannot take an already-allocated array and reallocate it to a new size without losing the data in it.
Thus, if you (for example) have an allocatable array FOO with 16 values in it, and you want to add space for 16 more, you have to first copy those 16 values into a temporary array, deallocate FOO and then allocate it with size 32, and copy the saved values back into it from the temporary array.
This means that, when you allocate the array, you have to allocate it as the maximum size that you're going to use until you deallocate it, rather than allocating some of it now and more of it later.
(I also disagree with what appears to be the authors' claim that this is somehow different from "dynamic allocation". It may be different from how dynamic allocation is implemented in certain languages, but that's not the same thing at all.)
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.
(I've been known to use the std::vector reallocation model in my own code, with an additional final "trimming" step to reduce the "allocated" length to the "in-use" length.)
.
- Follow-Ups:
- Re: allocatable array *not* equivalent to dynamic allocation?
- From: glen herrmannsfeldt
- Re: allocatable array *not* equivalent to dynamic allocation?
- References:
- Prev by Date: Re: allocatable array *not* equivalent to dynamic allocation?
- Next by Date: 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
|