home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / os2 / programm / 7912 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.8 KB  |  51 lines

  1. Newsgroups: comp.os.os2.programmer
  2. Path: sparky!uunet!newsflash.concordia.ca!mizar.cc.umanitoba.ca!access.usask.ca!sue!phenix.cc.uregina.ca!craig
  3. From: craig@phenix.cc.uregina.ca (Craig Knelsen)
  4. Subject: Re: Does OS/2 support Shared Memory?
  5. Message-ID: <1993Jan22.193214.465937@sue.cc.uregina.ca>
  6. Sender: news@sue.cc.uregina.ca
  7. Date: Fri, 22 Jan 1993 19:32:14 GMT
  8. Reply-To: craig@phenix.cc.uregina.ca (Craig Knelsen)
  9. References: <C17Kwo.7E7@techbook.com>
  10. Organization: Does it matter?
  11. Lines: 38
  12.  
  13. In article <C17Kwo.7E7@techbook.com> tonyb@techbook.com (Tony Bennett) writes:
  14. >If this is in the FAQ, I'm sorry.  
  15. >Unix has the concept of shared memory, that is multiple programs accessing a
  16. >common area of memory.  Does OS/2 support that concept and if so what functions
  17. >are used...  a little snippet of code using those functions would be
  18. >very helpfull.
  19. >Thanks in Advance.
  20.  
  21. Yes, OS/2 1.3 and 2.0 support shared memory. For OS/2 2.0:
  22.  
  23. #define INCL_DOSMEMMGR
  24. #include <os2.h>
  25.  
  26.     void *sh_mem, *some_mem;
  27.  
  28.     /* --- Allocate 16K --- */
  29.     DosAllocSharedMem(&sh_mem, "\\SHAREMEM\\whatever", 16384,
  30.               PAG_READ | PAG_WRITE);
  31.  
  32.     /* --- Set it up for suballocation --- */
  33.     DosSubSetMem(sh_mem, DOSSUB_INIT | DOSSUB_SPARSE_OBJ, 16384);
  34.  
  35.     /* --- Allocate some memory --- */
  36.     DosSubAllocMem(sh_mem, &some_mem, 1024);
  37.  
  38. For another process to access the shared memory:
  39.  
  40.     DosGetNamedSharedMem(&sh_mem, "\\SHAREMEM\\whatever",
  41.              PAG_READ | PAG_WRITE);
  42.  
  43. Of course, error checking should be performed on all Dos API calls.
  44. You don't need to suballocate it, its just one way of using shared memory.
  45. You will probably also want to create a mutual exclusion semaphore to
  46. control access to the shared memory.
  47. -- 
  48.  
  49. Craig Knelsen        craig@phenix.cc.uregina.ca
  50.             Craig_Knelsen@f1096.n140.z1.fidonet.org
  51.