Mainly used Boost when I tried to write ROS from scratch, trying to create an IPC framework.
Why did the Boost library come from? Why is it not part of STL?
The Boost library originated as a collection of high-quality, peer-reviewed C++ libraries aimed at extending the functionality of the Standard Template Library (STL) and providing solutions to common programming problems. It was established in 1998 by a group of C++ developers who saw a need for reusable components that were not covered by the STL or the C++ Standard Library at the time.
Boost serves as a testing ground for new features that might later be considered for inclusion in the C++ Standard Library. For example:
Smart pointers (shared_ptr, unique_ptr) first appeared in Boost and were later incorporated into C++11.
Regex library was in Boost before becoming part of the standard in C++11.
Boost.Asio (for asynchronous I/O) influenced the std::async features introduced in later versions of C++.
In the traditional programming model an operating system has multiple processes running and each process has its own address space. To share information between processes we have several alternatives:
Two processes share information using a file. To access to the data, each process uses the usual file read/write mechanisms. When updating/reading a file shared between processes, we need some sort of synchronization, to protect readers from writers.
Two processes share information that resides in the kernel of the operating system. This is the case, for example, of traditional message queues. The synchronization is guaranteed by the operating system kernel.
Two processes can share a memory region. This is the case of classical shared memory or memory mapped files. Once the processes set up the memory region, the processes can read/write the data like any other memory segment without calling the operating system’s kernel. This also requires some kind of manual synchronization between processes.
Video quality is bad but code is easy to understand
You need to use this in combination with mappedRegion.
Some
shared_memory_object class from Boost Interprocess is used to represent a portion of shared memory that can be accessed by multiple processes.
The truncate method is called to allocate memory for the shared memory object.
The mapped_region class from Boost Interprocess is used to map a region of the shared memory object into the process’s address space
Publisher
Subscriber
I was running into bus errors with this implementation and could attribute it to
when it came to the subscriber.
Ahh, it’s beca
I don’t run into this issue when using a managed shared memory object.
Managed Shared Memory
Tip
Use this if you need to dynamically allocate shared memory. However, if you don’t need, just use shared memory object.
The managed_shared_memory object has an internal memory allocator that automatically manages how space is allocated and reused.
You can dynamically allocate and deallocate memory within the segment using construct() and destroy()
For each segment, you need up with a new name that you use to query
Notice below that we have 2 names:
"SharedMemory": Shared memory name
"SharedBuffer": The name of the buffer
This is exactly how the memory alignment issue is abstracted away from you.
The difference
With shared_memory_object, the entire shared memory segment is treated as a raw block of memory.
In contrast, managed_shared_memory is more like a memory manager for shared memory. Instead of just being a raw block of bytes, it allows you to dynamically allocate and deallocate memory within the shared segment, similar to how a heap manager works in a regular program.
Other difference: When you use managed_shared_memory, you don’t explicitly specify read_write or read_only like you do with shared_memory_object. Instead, you only specify whether you’re creating or opening the shared memory segment, and Boost internally handles the memory access permissions for you.