Extended ALLOCATE statement
FTN95 allows you to access memory that was created
in another process. The keyword SHARENAME is provided as an FTN95 extension to
the standard ALLOCATE command in order to create memory in one process that can
be accessed from another. The same keyword can also be used to create a file
FTN95 also allows you to access memory that was created elsewhere in the same
process via the keyword ABSOLUTE_ADDRESS as descibed below.
Sharing memory between different processes
In the following illustration we create two programs
that share common memory. The two programs (called shareA and shareB) are listed
below. After compiling the programs using FTN95, the operation is as follows...
1. Start up program shareA.
2. Start up program shareB in a separate
Command Prompt window.
3. Type a message as input into the instance of
4. View the same message as it appears as output in instance of
The two programs use a common semaphore in order to synchronise
Here is the code for shareA.f90...
print*, "Type a message to send. Do not use spaces..."
print*, "Read the message then press any key to terminate"
Here is the code for shareB.f90...
print*, "Waiting for message..."
print*, "Press any key to terminate"
FTN95 also provides for the file-mapping of memory using the same keyword
Here is some sample code to illustrate how it works. When you run the
following program, the relevant file is created on the first run and there
is no output. On the second run, the file now exists and its content is output.
character(*),parameter:: myData = "C:\TechSupport\test.dat"
logical file_exists@, exists
exists = file_exists@(myData)
if(.NOT. exists) then
msg = "Data created!"
If the drive letter for the path is lower case then the file is mapped
for reading only. A file mapping occurs when the second character of the
SHARENAME is a colon, otherwise you get inter-process shared memory without file
De-allocating SHARENAME memory
By default the system releases shared memory when all processes accessing that
memory have terminated. In exceptional circumstances you may wish to call
DEALLOCATE for this memory allocation, in which case you must first call the
subroutine ENABLE_DEALLOCATE@ (giving the name of the allocated variable)
before calling DEALLOCATE.
For Win32 and x64 platforms, an FTN95 ALLOCATE statement can take the keyword
argument ABSOLUTE_ADDRESS=addr where addr is the INTEGER KIND(7) address
obtained from the LOC of some object. Here is an illustrative example.
addr = LOC(x)
x = 3.14159