- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
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
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page