home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mint095b.zoo / doc / shm.doc < prev    next >
Text File  |  1992-07-19  |  3KB  |  73 lines

  1. Shared Memory and How To Use It
  2.  
  3. MiNT has a special directory, U:\SHM, which provides a place for
  4. programs to advertise memory that they are offering to share.
  5. To create a shared memory file, a program uses the Fcreate call
  6. to create a file in U:\SHM, e.g.:
  7.  
  8. fd = Fcreate("U:\\SHM\\MY.SHARE", 0);
  9.  
  10. It then uses an Fcntl call to attach a block of memory (previously
  11. allocated by Malloc or Mxalloc) to the file:
  12.  
  13. blk = Malloc(128L);
  14. Fcntl(fd, blk, SHMSETBLK);
  15.  
  16.  
  17. Several things should be noted when creating a shared memory
  18. file:
  19.  
  20. (1) The file's attributes must be 0. Read-only shared memory, or
  21. shared memory with other attributes, is not yet implemented,
  22. but may be in the future.
  23.  
  24. (2) Two shared memory files cannot have the same name. An attempt
  25. to create a new shared memory file with the same name as an
  26. existing one will fail with an access denied error (EACCDN).
  27.  
  28. (3) Once the block of memory has been attached to the file, it
  29. may be accessed by any application that opens the file.
  30.  
  31. (4) A shared memory file (and associated block) remain allocated
  32. even after the program which created it terminates. It can be
  33. deleted (and the associated memory freed) with an Fdelete()
  34. system call.
  35.  
  36. (5) The size of the shared memory file will be the actual size
  37. of the memory block. This may be somewhat larger than the
  38. size requested in the Malloc or Mxalloc request, due to memory
  39. rounding.
  40.  
  41.  
  42. To use a shared memory block, a client application must open
  43. the file and use the SHMGETBLK Fcntl to gain access to it.
  44. For example:
  45.  
  46. fd = Fopen("U:\\SHM\\MY.SHARE", 2);
  47. blk = Fcntl(fd, 0L, SHMGETBLK);
  48.  
  49. Things to note:
  50.  
  51. (1) The address of the shared memory block is returned by the
  52. Fcntl call. NOTE THAT THIS ADDRESS MAY BE DIFFERENT FOR
  53. DIFFERENT PROGRAMS. That is, a shared memory block that appears
  54. at address 0x01000100 in one program may appear at address
  55. 0x0007f000 in another. In particular, shared memory blocks
  56. should not contain absolute addresses (e.g. pointers).
  57.  
  58. (2) The extra argument passed to Fcntl is reserved for future
  59. expansion; use 0L for now to ensure compatibility with
  60. future versions of MiNT.
  61.  
  62. (3) The mode argument in the Fopen function must be an accurate
  63. reflection of how the program plans to use the memory; read and
  64. write access permissions will be enforced in future versions
  65. of MiNT.
  66.  
  67. (4) If no SHMSETBLK has been made for the file, a SHMGETBLK Fcntl
  68. will return a NULL pointer to indicate an error.
  69.  
  70. (5) If a program is finished with a shared memory block and no
  71. longer wishes to use it, it should call Mfree() with the address
  72. of the block (i.e. the address returned by Fcntl(fd, 0L, SHMGETBLK)).
  73.