Pointers can be used to allocate new memory. In Fortran 90, they were needed to allocate memory to a component of a derived type, since components could not be allocatable. (That restriction is removed in Fortran 2003 and in most F95 compilers.) Pointers can also be used to simply "point" to memory that has already been allocated, as in the example I gave earlier. I don't think this use of pointers should take up much time, but this should be tested.
Vivek Rao
--- On Thu, 6/24/10, Greenberg, Naomi <[log in to unmask]> wrote:
> From: Greenberg, Naomi <[log in to unmask]>
> Subject: Re: Memory management question
> To: [log in to unmask]
> Date: Thursday, June 24, 2010, 3:42 PM
> I'll try to clarify with an example.
> What I want to do is replace:
> Real, allocatable :: array1(:),
> array2(:), array(3)
> Allocate (array1(7000))
> Allocate (array2(444))
> ...
> Deallocate (array1)
> Allocate (array1(33333))
> Etc. with something like
> Initialize up front, once: allocate Memory(100000)
>
> Real, allocatable :: array1(:),
> array2(:), array(3)
> Call allocMemMgr ( 7000, array1 )
> Call allocMemMgr ( 444, array2 )
> Etc. and have array1(100) be addressable in the main
> program. The only thing I can think of is having the
> manager return a start location and having the user of this
> manager explicitly use Memory(startLoc:startLoc+size)
> instead of an array.
>
> Even were I to use equivalence, I'd have
> to declare each array a fixed size before equivalencing it
> to Memory(startLoc), wouldn't I? And this size changes
> during the program. So equivalence won't work.
> I'm no expert on pointers, but I thought they were
> dynamically allocated as well, which would defeat my
> purpose. This application will be running for many days and
> will be dividing a huge matrix into pieces of varying sizes,
> doing operations on them, and then moving on to process
> other pieces of the matrix.
>
> Thanks,
> Naomi
>
> -----Original Message-----
> From: Fortran 90 List [mailto:[log in to unmask]]
> On Behalf Of Peter Shenkin
> Sent: Thursday, June 24, 2010 3:22 PM
> To: [log in to unmask]
> Subject: Re: Memory management question
>
> On Thu, Jun 24, 2010 at 2:49 PM, Ted Stern <[log in to unmask]>
> wrote:
> > On 24 Jun 2010 11:40:59 -0700, Vivek Rao wrote:
> >>
> >> Hello.
> >>
> >> If x(:) is your big array, in Fortran 90+ you can
> define a pointers x1(:), x2
> >> (:) etc. that refer to sections of it, for
> example
> >>
> >> allocate (x(1000000)
> >> x1 => x(1:300000)
> >> x2 => x(300001:1000000)
> >>
> >> Vivek Rao
> >
> > Naomi was specifically asking how to avoid slowdowns
> due to use of
> > pointers.
>
> Not the way I read her email.
>
> I thought she was asking how to avoid slowdowns due to
> dynamic allocation.
>
> But I have to say that I've never met anyone who tried to
> outwit the
> system's dynamic allocator who came to a good end. The
> system Naomi is
> suggesting is what we had to do in the bad old days, when
> we'd malloc
> a huge array in C and find some kludgy way to equivalence
> Fortran
> arrays to it.
>
> -P.
>
>
> __________ Information from ESET NOD32 Antivirus, version
> of virus signature database 5226 (20100624) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
> __________ Information from ESET NOD32 Antivirus, version
> of virus signature database 5226 (20100624) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
|