Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

allocating memory to strings

keith_shaw
Beginner
996 Views
Is there anyway to allocate memory to strings in Fortran?

I'm writing a DLL and need to pass strings to it. At the moment i am passing pointers to strings defined in Fortran as:
Character*250, target :: StringName

This works but very inconsistently. The DLL will never actually pick up the full length of this string, usually only around the first 100 characters of it, which is clearly not good enough.

Does anyone know a way i might either fix this problem, or get around it by doing something different? I thought allocating memory to a string and passing the location of the memory might work but i dont know how to do this.

Incidentally the DLL is written in Delphi 6.

Any help greatly appreciated.

Regards,
Keith
1 Reply
Jugoslav_Dujic
Valued Contributor II
996 Views
If you declare it with 250 and it really receives only 100, there's something fishy somewhere.

You can't declare strings of allocatable length in fortran 95 (you will in f2000 but no compiler supports it yet). You can allocate an array of characters, though. It will have the same layout in memory as one long string and you can even perform some same operations on it (READ and WRITE, but not concatenation and assignment IIRC).

Further, you can declare a target/pointer pair with different lengths:
CHARACTER,ALLOCATABLE,TARGET::  sss(:)
CHARACTER(ZILLION),POINTER::    psss
ALLOCATE(sss(ENOUGH))
psss=>sss(1)
psss="Your long text here"

Note that ZILLION can be a large number (keep it reasonably small to improve speed of operations), but only ENOUGH bytes will be really allocated.

Jugoslav
0 Kudos
Reply