home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.os2.programmer
- Path: sparky!uunet!newsflash.concordia.ca!mizar.cc.umanitoba.ca!access.usask.ca!sue!phenix.cc.uregina.ca!craig
- From: craig@phenix.cc.uregina.ca (Craig Knelsen)
- Subject: Re: Does OS/2 support Shared Memory?
- Message-ID: <1993Jan22.193214.465937@sue.cc.uregina.ca>
- Sender: news@sue.cc.uregina.ca
- Date: Fri, 22 Jan 1993 19:32:14 GMT
- Reply-To: craig@phenix.cc.uregina.ca (Craig Knelsen)
- References: <C17Kwo.7E7@techbook.com>
- Organization: Does it matter?
- Lines: 38
-
- In article <C17Kwo.7E7@techbook.com> tonyb@techbook.com (Tony Bennett) writes:
- >If this is in the FAQ, I'm sorry.
- >Unix has the concept of shared memory, that is multiple programs accessing a
- >common area of memory. Does OS/2 support that concept and if so what functions
- >are used... a little snippet of code using those functions would be
- >very helpfull.
- >Thanks in Advance.
-
- Yes, OS/2 1.3 and 2.0 support shared memory. For OS/2 2.0:
-
- #define INCL_DOSMEMMGR
- #include <os2.h>
-
- void *sh_mem, *some_mem;
-
- /* --- Allocate 16K --- */
- DosAllocSharedMem(&sh_mem, "\\SHAREMEM\\whatever", 16384,
- PAG_READ | PAG_WRITE);
-
- /* --- Set it up for suballocation --- */
- DosSubSetMem(sh_mem, DOSSUB_INIT | DOSSUB_SPARSE_OBJ, 16384);
-
- /* --- Allocate some memory --- */
- DosSubAllocMem(sh_mem, &some_mem, 1024);
-
- For another process to access the shared memory:
-
- DosGetNamedSharedMem(&sh_mem, "\\SHAREMEM\\whatever",
- PAG_READ | PAG_WRITE);
-
- Of course, error checking should be performed on all Dos API calls.
- You don't need to suballocate it, its just one way of using shared memory.
- You will probably also want to create a mutual exclusion semaphore to
- control access to the shared memory.
- --
-
- Craig Knelsen craig@phenix.cc.uregina.ca
- Craig_Knelsen@f1096.n140.z1.fidonet.org
-