Re: Returning a dynamic character array based on input length
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: Returning a dynamic character array based on input length         

Group: comp.lang.fortran · Group Profile
Author: George McBane
Date: Sep 10, 2008 18:20

Richard Maine wrote:
>
> Yes. Heck, it wasnt too awfully long ago that Fortran had *NO* dynamic
> allocation of any kind. Dynamic allocation wasn't standard in Fortran
> until f90. Prior to that, some codes used nonstandard nonportable hacks
> of various kinds.

I work regularly with a legacy F77 program that has author-written
DMA. (I'm not the author.)
The program structure permits a stack sort of allocation.
At the beginning you allocate one humongous array X, and
put the array and an integer pointer to the "next available element"
in common. When you need some more memory, you start loading
stuff in the next available element, and update the pointer to
the next place above where you filled. To deallocate, you just set
the pointer back where it was. You can only free stuff
from the top of the stack down; no cutting holes in the middle.
But that's okay for the way this calculation works. To pass a workspace
array of length 100 to a subroutine, you do
temp = nextavail
nextavail = nextavail+100 ! requests allocation
call checkstorage(nextavail) !checks to make you've not overflowed
call workroutine(x(temp)) ! passes array address
nextavail = temp !deallocates

The reason I'm writing this: this simple scheme IS portable.
I've used it on a dozen architectures with almost as many
Fortran compilers and it has never caused trouble. So for a limited
class of needs, there was a portable way to do allocations.

-George <- likes F90 allocations better :-)
no comments
diggit! del.icio.us! reddit!

RELATED THREADS
SubjectArticles qty Group
Access 97 using ODBC returning SQL server ntext fields dont return the full datamicrosoft.public.sqlserver.odbc ·