soccer jersey forums.silverfrost.com :: View topic - Sharing inter-process memory with FTN95 under Win32
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sharing inter-process memory with FTN95 under Win32

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> KBase
View previous topic :: View next topic  
Author Message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8011
Location: Salford, UK

PostPosted: Wed Apr 08, 2009 2:22 pm    Post subject: Sharing inter-process memory with FTN95 under Win32 Reply with quote

From version 5.30 of FTN95 you can 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.

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 shareA.
4. View the same message as it appears as output in instance of shareB

The two programs use a common semaphore in order to synchronise the events.

Here is the code for shareA.f90...

Code:

include <windows.ins>
integer(2) c
character,pointer::msg*80
  allocate(msg, SHARENAME="MyMemory")
  print*, "Type a message to send. Do not use spaces..."
  read*, msg
  call SIGNAL_SEMAPHORE@("MySemaphore")
  print*, "Read the message then press any key to terminate"
  call get_key@(c)
  deallocate(msg)
end


Here is the code for shareB.f90...

Code:

include <windows.ins>
integer(2) c
character,pointer::msg*80
  allocate(msg, SHARENAME="MyMemory")
  print*, "Waiting for message..."
  call WAIT_ON_SEMAPHORE@("MySemaphore")
  print*, msg(1:len_trim(msg))
  print*, "Press any key to terminate"
  call get_key@(c)
end


The planned new FTN95 feature for the file-mapping of memory uses the same keyword SHARENAME, but is not functioning as intended and will now be included in the next release of FTN95.

Here is some sample code to illustrate what will be available in the next release. When you run the following program, the relevant file will be created on the first run and there is no output. On the second run, the file now exists and its content is output.

Code:
character,pointer::msg*80
character(*),parameter:: myData = "C:\TechSupport\test.dat"
logical file_exists@, exists
exists = file_exists@(myData)
allocate(msg, SHARENAME=myData)
if(.NOT. exists) then
  msg = "Data created!"
else
  print*, msg
endif
end


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 mapping.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> KBase All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group