In this recipe, we use the POSIX (short for Portable Operating System Interface) API to work with shared memory. This is a flexible and fine-grained C API, with lots of parameters that can be tuned or configured. Our goal is to hide the complexity of this low-level API by implementing a more convenient and type-safe C++ wrapper on top of it. We are going to use the RAII (short for resource acquisition is initialization) idiom to make sure all allocated resources are properly deallocated and we do not have memory or file descriptor leaks in our application.
We define a templated SharedMem class. The template argument defines a data type that is stored in our shared memory instance. This way, we make instances of the SharedMem ...