home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / shmserve.zip / read.me next >
Text File  |  1998-12-04  |  5KB  |  116 lines

  1. Shared Memory Suballocation Sample Code v1.1
  2. For OS/2 Warp
  3.  
  4. ==============================================
  5. Use PKUNZIP to unzip the contents of the ZIP file
  6. into a single directory.
  7.  
  8. ==============================================
  9. To RUN:
  10. Open an OS/2 Window session, and execute the server
  11. SHMSERVE
  12.  
  13. It will perform some processing, and then wait for you
  14. to run one or more client programs (in other OS/2 windows):
  15. SHMCLIENT <command parameters>
  16.  
  17. ==============================================
  18. To Compile/Link:
  19. We used the IBM VisualAge C++ Compiler to produce these samples.
  20. To compile and link these files, simply type:
  21. nmake shmserve.mak
  22.  
  23. ==============================================
  24. Files required:
  25.  
  26. SHMSERVE.EXE   Executable sample Server
  27. SHMCLIEN.EXE   Executable sample Client
  28.  
  29. SHMSERVE.C     Source Code, Server
  30. SHMCLIEN.C     Source Code, Client
  31. SHMSERVE.H     Include File, Server and Client
  32. SHMSERVE.DEF   Link Definition File, Server
  33. SHMCLIEN.DEF   Link Definition File, Client
  34. SHMSERVE.MAK   make file
  35.  
  36. READ.ME        These instructions
  37. ==============================================
  38.  
  39. You will find detailed documentation within the C programs themselves.
  40.  
  41. In summary:
  42.  
  43.     This code sample illustrates the usage of suballocated shared memory
  44.     between two or more processes.
  45.  
  46.     shmserve.exe is the Server Process and should be running at all times.
  47.     shmclien.exe is the Client Process and can be run multiple times.
  48.  
  49.     A Named-Shared memory segment, called SHMSERVE.SHM is created by the
  50.     Server Process.  It is fairly small and includes various control
  51.     values found in SERVERCONTROLREC.  During startup, the Server Process
  52.     sub-allocates an initial pool of shared memory, and prepares it for
  53.     suballocation.  The address of this pool of memory is stored in the
  54.     (smaller) Named-Shared memory segment for rapid access by clients.
  55.  
  56.     When a Client Process is run, it attempts to read the Named-Shared
  57.     memory segment, whose presence signifies that a Server Process is
  58.     running.  The Client Process then tries to add some application
  59.     data (GLOM) to the pool of memory.
  60.  
  61.     Suballocated memory is more efficient in the use/reuse of memory,
  62.     than static blocks/pages of memory, especially with dynamic data
  63.     usage patterns.
  64.  
  65.     You can use the Client Process to Add, Delete, Read, or List
  66.     application (GLOM) data to/from the Shared memory area.
  67.  
  68.     You can also inquire the values in the Server Control record.
  69.  
  70.     Client Commands:
  71.        To add GLOM Data (Name and value):
  72.           SHMCLIEN A Glom_name glom_value
  73.        To delete 1st occurrence of GLOM Data (Name):
  74.           SHMCLIEN D Glom_name
  75.        To list GLOM Data (Names and values):
  76.           SHMCLIEN L
  77.        To Inquire the contents of the Server Control Record
  78.           SHMCLIEN I
  79.  
  80.     You should be able to notice that Suballocation usage will
  81.        increase/decrease, as GLOM items are added/removed.
  82.     Each time you reach a certain threshold, additional memory
  83.        is allocated.
  84.  
  85.     You should consider altering the values in the shmserve.h
  86.     file to see changes allocation behavior:
  87.  
  88. #define INIT_SUBALLOC_MEM_SIZE    32768L
  89. might be changed to:
  90. #define INIT_SUBALLOC_MEM_SIZE    240L
  91.  
  92. and
  93.  
  94. #define GROW_SUBALLOC_MEM_SIZE    32768L
  95. might be changed to:
  96. #define GROW_SUBALLOC_MEM_SIZE    240L
  97.  
  98.     Notice that this sample code includes additional logic to help
  99.     prevent multiple servers from running, as well as starting a server
  100.     process while old client processes are still hanging around:
  101.  
  102.     Shared memory is controlled by the operating system layer maintaining
  103.     a usage-count (of processes).  Shared memory does not actually get
  104.     released until usage-count goes back to zero.  Therefore a server
  105.     process may be able to shut down and free its shared memory, but if
  106.     a client process is still running, then usage-count is non-zero and
  107.     the shared memory still exists.
  108.  
  109.     The server process requires that it successfully Create the named
  110.     shared memory segment (not simply successfully open it).  Each
  111.     client process can only Open the named shared memory segment (not
  112.     Create), and requires that the original Server process be still
  113.     running.  Note that the original Server process indicates that it
  114.     has been shut down, when it changes the server control record,
  115.     Server_Status parameter to non-zero.  Clients require this value
  116.     to be zero, in order to successfully start up.