1 min read

Things I learned calling shm_open() on a Mac

  1. The shared memory object name passed to shm_open() must contain only one slash (the leading slash).
  2. The object name passed to shm_open() must be at most 31 characters long, including the leading slash and leaving out the trailing null. If it's longer, you get an error.
  3. You can't write() to the file descriptor returned by shm_open(). Attempting to do so results in a Device not configured error.
  4. If you ftruncate() the shared memory object more than once, that's an error — even if you do ftruncate() to the result of different shm_open() calls with the same object name in different runs of the same program.

Unrelated to shm_open(), but as part of the same project, I learned that the correct way to throw an exception in C++ is throw exception(...), not throw new exception(...). I am too used to seeing C# and Java code snippets where the latter is correct.