1. First checks
- Look at the start-up report for
ShmemDriver: Stream '<name>' Init filename '<file>' Success. If it is missing, or an error appears instead, use the table below. - Make sure
"filename"and"size"are both in the driver section. Neither has a default in the code; a missing value is not reported. - Compare the file name and size in both programs character by character. They must be identical.
- Check the block counters of the block in DIPanel or System Layout. Note that the input counter
msgCounterof a shmem stream rises on every read cycle, whether or not the other process wrote anything, so it proves that the stream runs, not that data flows. Watch the block's data values instead. - Check the block size in the ICD against
size. See section 4.
2. Message reference
| Message | Cause | What to do |
|---|---|---|
ShmemDriver: Stream '<name>' Init filename '<file>' Success (info) | The shared memory was created, or an existing one with that name was opened and mapped. | Nothing: normal. |
ShmemDriver: Stream '<name>' create filename '<file>' failed (error) | The shared memory could not be created. Windows: CreateFileMapping failed (name invalid or in use by an object of a different kind, access denied). Linux/macOS: shm_unlink / shm_open / ftruncate failed (no permission on /dev/shm, an old segment owned by another user, size too large, or /dev/shm full). | See section 3. |
ShmemDriver: Stream '<name>' mapping filename '<file>' failed (error) | The segment exists but mapping it into the engine's address space failed. Typical: size is larger than the existing segment (another process created it smaller), or the memory limit is reached. | Make size equal on both sides, or equal to the creating process's size. On Windows the engine also prints MapViewOfFile failed: <Windows error number> on the console. |
ShmemDriver: Stream '<name>' openning filename '<file>' failed (error; the word "openning" is spelled like that in the program) | The segment exists already but could not be opened (Windows: OpenFileMapping failed, normally access denied because the other process runs with higher rights or in another session). | Run both programs with the same user/rights and in the same Windows session. See section 5. |
Stream: '<name>': block '<block>': timing <N>us > system minor frame <M>us; data may be lost. (warning) | An input block has a numeric framePerMS longer than the minor frame. | See section 7. |
3. Name, who creates it, and how the segment is opened
- The engine creates the segment if it does not exist yet, otherwise it opens the existing one. On start (
OnInit) the driver first checks whether a segment with that name exists; if it does, it is reused; if not, it is created withsizebytes. - Start order matters on Windows. If the other process starts first and creates the segment with a different size, the engine opens that one. If the engine asks for a larger size than the existing segment has, mapping fails. Start the process that defines the size first, or use the same size in both.
- On Linux/macOS the creating call first deletes an existing segment with the same name and creates a new one. A process that already had the old segment open keeps a mapping to the old, now unlinked memory and no longer sees the engine's data. After an engine restart (or reset) restart the other process, or have it open the segment late and re-open it when needed.
- The file name: maximum 31 characters (longer names are cut). Use only letters and digits; no spaces, slashes or other characters (the library expects an alpha-numeric name; on Linux/macOS it adds a leading
/itself, so write"mydata", not"/mydata", and the segment appears as/dev/shm/mydataon Linux). - The names are case sensitive on Linux. On Windows the name lives in the object namespace of the session; a name used by another program for a different kind of object makes creation fail.
- The segment is also released when the engine closes. On Linux the destructor removes (unlinks) the name, so when the engine exits the other side loses it.
4. Size mismatch
| Situation | Result | Fix |
|---|---|---|
size in the engine is smaller than the other process uses | The other process (which maps more) reads or writes beyond what the engine maps. Data beyond size is not seen by the engine; the other process may fail to map or read zeros. | Use the same size on both sides. |
size in the engine is larger than the existing segment | Mapping fails: mapping filename '...' failed. | Reduce size or recreate the segment with the correct size (restart both programs in a defined order). |
size larger than the blocks | Works; the extra bytes are unused. | Normal. Keep the block sizes of the ICD within size. |
Blocks (all in one stream) add up to more than size | Part of the data lies outside the mapped memory. | Set size to at least the sum of the stream's input and output block sizes, or split into two streams with two files. |
| Layout different in the two programs (field order, packing / alignment, byte order) | Values look scrambled even though the size is right. | Use the same structure definition in both (same packing, fixed-width types). Do not use long / bool / pointers in the shared structure. |
5. Permissions, sessions and stale files
- Windows: a program running as administrator can create a segment that a normal program cannot open (access denied, see "openning ... failed"). Run both as the same user. A Windows service runs in session 0, and a user program in another session; shared memory created without the
Global\prefix is private to the session, so the two will not see each other. The driver uses the name exactly as given. - Linux: segments are files under
/dev/shm, created with mode 0755. A segment left over from a crashed process or another user may be unwritable for the engine (create fails). Look atls -l /dev/shm, and remove a stale file withrm /dev/shm/<name>when no program uses it. Docker: containers have their own/dev/shm(64 MB by default); use--ipc=hostor share a volume on/dev/shmto exchange data, and enlarge it with--shm-sizefor big sizes. - Stale segment after a crash (Linux): if the engine crashes, the name is not removed. At the next start the engine deletes and recreates it (so the other process must be restarted too). If a different program crashed and left the file, the engine's recreation removes it as well.
- 32/64-bit: a 32-bit and a 64-bit process can share the segment on one machine, but the structure inside must not use
longor pointers (size differs between the two). A 32-bit process cannot map a very large segment. - Different machines / network: shared memory works only between processes on the same computer (or the same container IPC namespace). For other computers use a socket driver.
6. No synchronization: torn reads
The driver provides no locks, flags or sequence numbers. The engine copies bytes to and from the memory, and the other process can read or write at the same time. This means:
- A block may be read while the other side is half way through writing it (a torn read): some fields from the old frame, some from the new one.
- Both sides may write the same area and overwrite each other.
- Fixes in the protocol (the interface is yours to define): give each direction its own region (separate blocks), put a sequence counter at the start and the same value (or a checksum) at the end of the block and let the reader accept the data only when both are equal and unchanged after reading, or double-buffer with an index field. Write the sequence/valid field last.
- Do not rely on the block's message counter to detect new data (see First checks).
- The data is shared at memory speed; there is no event when new data arrives. The reader sees changes only on its next read cycle, so data reaches the other program up to one cycle late.
7. framePerMS for input blocks
For an input block ("direction": "in") use "framePerMS": -1:
-1: the stream reads the memory every minor frame. Recommended.0: the block is disabled. The block never changes and no error is printed. A very common reason for "I see no data".- a number (ms or
Nhz): the memory is read only at that rate. If the writer updates faster than that, updates are lost between reads, and a warning is printed when the period is longer than the minor frame.
See the note on framePerMS in the streams manual.
8. Other problems
| Symptom | Cause | Fix |
|---|---|---|
| No report line at all for the stream | The stream is not in streams.json, is disabled, or the driver name is misspelled (must be "ShmemDriver"). | Check streams.json. See How to Set Up Streams. |
| Other process reads zeros | Different file name (one letter, case, or a leading /), or the engine is on another Windows session. | Compare names; see section 3 and 5. |
| Other process worked before the engine was restarted, now sees old data (Linux) | The engine recreated the segment; the other process still maps the old one. | Restart the other process after the engine, or reopen the segment on each connection. |
| Name is cut or segment not found by the other program | Name longer than 31 characters. | Use a shorter name. |
| Looks like random bytes or shifted values | Layout mismatch (alignment/packing, endianness, data types of different width) between the two programs and the ICD. | Align the structure definitions; check the block definition in the ICD. |
| Values flicker between old and new | Torn reads (section 6). | Add sequence counters or double buffering. |
| Engine stops reading after reset | The segment is recreated on reset; the other process holds the old one. | Reopen on the other side after a reset. |
Message counters and error counters of every block are visible live in System Layout. Use the
receive hooks to validate data (for example a sequence check). The driver fields
filename and
size are described in the streams manual.