Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Even if your <code>shared_stuff</code> object is in shared memory, you are not writing the array to shared memory. You are allocating space with <code>malloc</code>, writing data to that space, and then putting pointers to that space into <code>shared_stuff</code>. <code>malloc</code> allocates space within the current process‘ normal address space, not in a shared memory segment you have created. You need to write the array contents to the shared memory.</p> <p>Presuming there is enough space for the array within the shared memory segment, you will have to manage the addresses yourself, not using <code>malloc</code>. (If there is not enough space, you must make the shared memory segment larger or convey the information in pieces over time.)</p> <p>You can place a variable-length array within the shared memory segment as follows.</p> <p>First, define a structure that contains all the “management” information you need, such as the array sizes:</p> <pre><code>struct StuffStruct { size_t NumberOfRows, NumberOfColumns; … Other information as desired. }; </code></pre> <p>Create a pointer to that structure and set it to point to the shared memory segment:</p> <pre><code>struct StuffStruct *Stuff = shm; // shm contains the address from shmat, performed previously. </code></pre> <p>Create a pointer to an array with the desired number of columns and set it to point into the shared memory segment after the initial structure:</p> <pre><code>int (*data_store)[NumberOfColumns] = (int (*)[NumberOfColumns]) ((char *) Stuff + sizeof *Stuff); </code></pre> <p>(Note for C purists: Yes, the C standard does not guarantee what happens when you do pointer arithmetic like this. However, any implementation providing shared memory support must provide support for this sort of pointer arithmetic.)</p> <p>Note that <code>sizeof *Stuff + NumberOfRows * NumberOfColumns * size(int)</code> <strong>must</strong> be no greater than the size of the shared memory segment. Otherwise you will overrun the shared memory segment in the next step.</p> <p>For the next step, fill the array with data: Assign values to the elements of <code>data_store</code> as for a normal two-dimensional array.</p> <p>In the server, set <code>Stuff</code> the same way. Then, after the client has written the shared memory segment, read the numbers of rows and columns from <code>Stuff</code>. Then set <code>data_store</code> the same way. Then read from <code>data_store</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload