A process allocates unnamed gettable shared memory by using DosAllocSharedMem with the object name (pszName parameter) set to NULL and the memory options (flag parameter) set to OBJ_GETTABLE. The allocating process must pass a pointer to the shared memory to another process. This is typically done by using some form of interprocess communication, such as a queue or a named pipe.
If an application allocates shared memory with the OBJ_GETTABLE option, it passes a pointer to the shared memory to the second process. The second process gets access to the shared memory by using DosGetSharedMem to validate the passed pointer.
The following code fragment allocates 24576 bytes (24KB) of unnamed gettable shared memory:
#define INCL_DOSMEMMGR /* Memory Manager values */ #include <os2.h> APIRET ulrc; PBYTE pb; ulrc = DosAllocSharedMem((PVOID *) &pb, (PSZ) NULL, 24576, fALLOC | OBJ_GETTABLE); /* gettable memory */
Once the memory is allocated, the process can pass the memory pointer to a second process through interprocess communication. Once the second process receives the pointer, it validates the memory with DosGetSharedMem, as shown in the following code:
#define INCL_DOSMEMMGR /* Memory Manager values */ #include <os2.h> APIRET ulrc; PBYTE pb2; ulrc = DosGetSharedMem(pb2, /* validating the memory allocated by */ /* the allocating process */ PAG_READ | PAG_WRITE);