pr_opensharedmemory.rst (1846B)
1 PR_OpenSharedMemory 2 =================== 3 4 Opens an existing shared memory segment or, if one with the specified 5 name doesn't exist, creates a new one. 6 7 8 Syntax 9 ------ 10 11 .. code:: 12 13 #include <prshm.h> 14 15 NSPR_API( PRSharedMemory * ) 16 PR_OpenSharedMemory( 17 const char *name, 18 PRSize size, 19 PRIntn flags, 20 PRIntn mode 21 ); 22 23 /* Define values for PR_OpenShareMemory(...,create) */ 24 #define PR_SHM_CREATE 0x1 /* create if not exist */ 25 #define PR_SHM_EXCL 0x2 /* fail if already exists */ 26 27 28 Parameters 29 ~~~~~~~~~~ 30 31 The function has the following parameters: 32 33 name 34 The name of the shared memory segment. 35 size 36 The size of the shared memory segment. 37 flags 38 Options for creating the shared memory. 39 mode 40 Same as passed to :ref:`PR_Open`. 41 42 43 Returns 44 ~~~~~~~ 45 46 Pointer to opaque structure ``PRSharedMemory``, or ``NULL`` if an error 47 occurs. Retrieve the reason for the failure by calling :ref:`PR_GetError` 48 and :ref:`PR_GetOSError`. 49 50 51 Description 52 ----------- 53 54 :ref:`PR_OpenSharedMemory` creates a new shared memory segment or 55 associates a previously created memory segment with the specified name. 56 When parameter ``create`` is (``PR_SHM_EXCL`` \| ``PR_SHM_CREATE``) and 57 the shared memory already exists, the function returns ``NULL`` with the 58 error set to ``PR_FILE_EXISTS_ERROR``. 59 60 When parameter ``create`` is ``PR_SHM_CREATE`` and the shared memory 61 already exists, a handle to that memory segment is returned. If the 62 segment does not exist, it is created and a pointer to the related 63 ``PRSharedMemory`` structure is returned. 64 65 When parameter ``create`` is 0, and the shared memory exists, a pointer 66 to a ``PRSharedMemory`` structure is returned. If the shared memory does 67 not exist, ``NULL`` is returned with the error set to 68 ``PR_FILE_NOT_FOUND_ERROR``.