ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / Process functions / Shared memory area functions
  • Managing the share mode
  • Correspondence between the name provided to fMemOpen and the opening in C
  • Managing the memory areas in UNICODE format
  • Positioning in the shared memory area
  • Closing the shared memory area
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Opens a memory zone shared between several applications.
Then, the content of memory area can be handled by fSeek, fRead and fWrite.
Example
// Create/Open a memory area shared between applications (1st application)
arrZoneID is associative array of int
Zone1ID is int
Zone1ID = fMemOpen("MySharedZone", 1024, shareGlobal, ...
foReadWrite, ModificationProcedure)
arrZoneID["MySharedZone"] = Zone1ID
...
// Create/Open a memory area shared
// between applications (2nd application) -
// no callback
Zone2ID is int
Zone2ID = fMemOpen("MySharedZone", 1024, shareGlobal)
// Write into the shared memory area
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 area is modified
PROCÉDURE 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))
WINDEVWEBDEV - Server codeLinux
llMemHdl is int
sFileName is string = fTempPath() + ["/"] + "ipc0"
fSaveText(sFileName, "")
sNameMemZone is string = Charact(3) + sFileName
llMemHdl = fMemOpen(sNameMemZone, 1024, shareGlobal)
 
// Equivalent code in C
// char * szZoneName = "/tmp/ipc0"
// int nSize;
// int nMem;
// key_t nKey;
// int nAccess = 0666;
// Opening in read/write
 
// nSize = 1024;
// nKey = ftok(szZoneName, 3);
// nMem = shmget(nKey, nSize, nAccess);
Syntax
<Result> = fMemOpen(<Memory area> , <Size> [, <Share> [, <Opening mode> [, <WLanguage procedure>]]])
<Result>: Integer
  • Identifier of the memory area.
    This identifier can be handled by the fxxx functions like an identifier of external file returned by fOpen.
  • -1 if an error occurred.
<Memory area>: Character string
Name of the shared memory area 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.
Linux The name of the memory area 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).
<Size>: Integer
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 area 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 area between the user sessions:
shareGlobalThe zone is shared between all the applications of all the computer sessions.
shareUser
(Default value)
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.
foReadThe 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 area, you must close the memory area (fClose) and re-open it with a different opening mode.
foReadWrite
(Default value)
The zone is opened in "read/write". You will be able to read and modify this zone.
foUnicodeOpen a file in UNICODE format. (For more details, see the Notes)
foWriteThe zone is opened in "write only". You will only have the ability to write into this zone.
<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 areas.
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.
Remarks

Managing the share mode

The share mode differs according to the versions of the operating systems:
  • Windows Vista and later: the <Share> parameter of fMemOpen is supported. The services and the users are located in a different space. To share a memory area 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 supported. Each session opened on the Terminal Server has a different memory space. The applications started in the same TSE session can share a memory area 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.
Linux

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 nSize;
int nMem;
key_t nKey;
int nAccess = 0666; // Open in read/write

nSize = 1024;
nKey = ftok(szZoneName+sizeof(char),(int) szZoneName[0]);
nMem = shmget(nKey, nSize , nAccess);

Managing the memory areas in UNICODE format

fMemOpen is used to read and write memory areas using UTF-16 or Little Endian Unicode. 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 area

When opening a shared memory area, the current position corresponds to the first byte of the zone.
This position can be modified by fSeek.

Closing the shared memory area

When the application does no longer need to access the shared memory area, 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.
Component: wd290std.dll
Minimum version required
  • Version 15
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 01/19/2023

Send a report | Local help