A process allocates unnamed giveable shared memory by using DosAllocSharedMem with the object name (pszName parameter) set to NULL and the memory options (flag parameter) set to OBJ_GIVEABLE. The process allocating the memory 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 a process allocates shared memory with the OBJ_GIVEABLE option, this process can validate the pointer in another process with DosGiveSharedMem.
The following code fragment allocates 24576 bytes (24KB) of unnamed giveable shared memory:
#define INCL_DOSMEMMGR /* Memory Manager values */ #include <os2.h> APIRET ulrc; PBYTE pb; ulrc = DosAllocSharedMem((PVOID *) &pb, (PSZ) NULL, 24576, /* amount of memory */ fALLOC | OBJ_GIVEABLE); /* giveable memory */
Once the memory is allocated, the allocating process can pass the memory pointer to a second process through interprocess communication. The second process need not use DosGetSharedMem; the second process can just use the shared memory.