allocating memory to strings

allocating memory to strings

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.


2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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:

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.


Leave a Comment

Please sign in to add a comment. Not a member? Join today