- Managing the share mode
- Correspondence between the name provided to fMemOpen and the opening in C
- Managing the memory zones in UNICODE format
- Positioning in the shared memory zone
- Closing the shared memory zone
In french: fMemOuvre
Opens a memory zone shared between several applications.
// Create/Open a memory zone shared between applications (1st application)
arrZoneID is associative array of int
Zone1ID is int
Zone1ID = fMemOpen("MySharedZone", 1024, shareGlobal, ...
arrZoneID["MySharedZone"] = Zone1ID
// Create/Open a memory zone shared
// between applications (2nd application) -
// no callback
Zone2ID is int
Zone2ID = fMemOpen("MySharedZone", 1024, shareGlobal)
// Write into the shared memory zone
fWrite(Zone2ID, "Hello, I am a WINDEV application!")
// The writing performed by the 2nd application triggers
// the call to the procedure in the 1st application
// Procedure called whenever the shared memory zone is modified
PROCEDURE ModificationProcedure(NameNotifZone is string)
ModifiedString is string
ModifiedString = fRead(arrZoneID[NameNotifZone], 1024)
Trace(StringBuild("The %1 string was written into the %2 zone", ModifiedString, NameNotifZone))
<Result> = fMemOpen(<Memory zone> , <Size> [, <Share> [, <Opening mode> [, <WLanguage procedure>]]])
- Identifier of the memory zone.
This identifier can be handled by the fxxx functions like an identifier of external file returned by fOpen.
- -1 if an error occurred.
<Memory zone>: Character string (with quotes)
Name of the shared memory zone that must be created or opened. This name must be the same in the different applications that access the zone.
The zone is automatically created if it does not exist.
The name of the memory zone must have the following format:
Charact(<Val>) + <Existing Unix file name>
where <Val> is an integer from 1 to 127 that corresponds to the second parameter of the "C" ftok() API (if the exchange must be performed with a process written in C).
Minimum size of the shared memory zone in bytes.
- If the zone already exists:
- if <Size> is equal to 0: this parameter is ignored and the size of the zone is returned by fSize.
- if <Size> is different from 0:
- if <Size> is too big, fMemOpen returns -1.
- the existing memory zone is opened with a size at least equal to the parameter (the actual size is defined by the operating system and it is returned by fSize).
- If the zone does not exist, it is created with a size at least equal to the parameter (the actual size is defined by the operating system and it is returned by fSize).
<Share>: Optional Integer constant
Mode for sharing the memory zone between the user sessions:
|shareGlobal||The zone is shared between all the applications of all the computer sessions.|
|The zone is shared between all the applications of the user session.|
<Opening mode>: Optional Integer constant
Constants used to define the access mode to the shared memory zone.
|foWrite||The zone is opened in "write only". You will only have the ability to write into this zone.|
|foRead||The zone is opened in "read only". You will only have the ability to read this zone.|
If this constant is used, to change the opening mode of the memory zone, you must close the memory zone (fClose
) and re-open it with a different opening mode.
|The zone is opened in "read/write". You will be able to read and modify this zone.|
|foUnicode||Open a file in UNICODE format. (See the Notes for more details)|
<WLanguage procedure>: Procedure name
Name of the WLanguage procedure ("callback" procedure) that will be automatically called if the memory zone is modified by another WLanguage application.
This procedure has the following format:
PROCEDURE <Procedure name>(<Zone name>)
The parameter of this procedure is optional. It must be used when a unique callback is used to receive the notifications of several shared memory zones.
The <Zone name> parameter will be prefixed by the "Global\" string if the zone was created with the shareGlobal constant and by the "Local\" string if the zone was created with the shareUser constant.
The share mode differs according to the versions of the operating systems:
- Linux, Windows 2000 and earlier: if there is a single space for creating the memory zone, the <Share> parameter of fMemOpen is ignored.
- Windows XP: the <Share> parameter of fMemOpen is effective if the service for quick change of user is enabled, otherwise it is ignored.
- Windows Vista and later: the <Share> parameter of fMemOpen is managed. The services and the users are located in a different space. To share a memory zone between a service and an application in a user session, the shareGlobal constant must be used.
- In Terminal Server: the <Share> parameter of fMemOpen is managed. Each session opened on the Terminal Server has a different memory space. The applications started in the same TSE session can share a memory zone created with the shareUser constant. Several applications located in different sessions can share a memory zone created by the shareGlobal constant.
- Windows: The administrator rights are required to access a Global memory zone in write mode or in read mode.
Correspondence between the name provided to fMemOpen and the opening in C
The two following code examples present the opening of a memory zone (named "myzone") in WLanguage and inC.
// Code in WLanguage
ZoneID is int
ZoneID = fMemOpen("myzone", 1024, shareGlobal)
// Equivalent code in C
char * szZoneName = "myzone";
int nAccess = 0666; // Open in read/write
nSize = 1024;
nKey = ftok(szZoneName+sizeof(char),(int) szZoneName);
nMem = shmget(nKey, nSize , nAccess);
Managing the memory zones in UNICODE format
fMemOpen is used to read and write memory zones in UNICODE "UTF-16" or in "little endian" format. At opening, the "current Unicode" mark (FFFE) is automatically read. At creation, it is automatically added.
Remark: The mechanism for automatic callback of a WLanguage procedure whenever the memory zone is modified by another application operates between WLanguage applications only.
Positioning in the shared memory zone
When opening a shared memory zone, the current position corresponds to the first byte of the zone.
This position can be modified by fSeek
Closing the shared memory zone
When the application does no longer need to access the shared memory zone, the access can be closed by fClose
. The zone is effectively destroyed once the last application accessing it has closed the zone. If no explicit call to fClose
is found in the code of the application, the closing will be automatically performed when the application ends.
This page is also available for…
Click [Add] to post a comment