libcamera v0.2.0
Supporting cameras in Linux since 2019
|
Helper class for allocating shared memory. More...
Public Member Functions | |
SharedMem (const std::string &name, std::size_t size) | |
Contstructor for the SharedMem. More... | |
SharedMem (SharedMem &&rhs) | |
Move constructor for SharedMem. More... | |
~SharedMem () | |
SharedMem destructor. More... | |
SharedMem & | operator= (SharedMem &&rhs) |
Move constructor for SharedMem. More... | |
const SharedFD & | fd () const |
Gets the file descriptor for the underlaying shared memory. More... | |
void * | mem () const |
Gets the pointer to the underlaying shared memory. More... | |
Helper class for allocating shared memory.
Memory is allocated and exposed as a SharedFD for use across IPC boundaries.
SharedMem allocates the shared memory of the given size and maps it. To check that the shared memory was allocated and mapped successfully, one needs to verify that the pointer to the shared memory returned by SharedMem::mem() is not nullptr.
To access the shared memory from another process the SharedFD should be passed to that process, and then the shared memory should be mapped into that process address space by calling mmap().
A single memfd is created for every SharedMem. If there is a need to allocate a large number of objects in shared memory, these objects should be grouped together and use the shared memory allocated by a single SharedMem object if possible. This will help to minimize the number of created memfd's.
libcamera::SharedMem::SharedMem | ( | const std::string & | name, |
std::size_t | size | ||
) |
|
inline |
Move constructor for SharedMem.
[in] | rhs | The object to move |
|
inline |
SharedMem destructor.
Unmaps the allocated shared memory. Decrements the shared memory descriptor use count.
|
inline |
Gets the file descriptor for the underlaying shared memory.
|
inline |
Gets the pointer to the underlaying shared memory.
Move constructor for SharedMem.
[in] | rhs | The object to move |