libcamera v0.2.0
Supporting cameras in Linux since 2019
Public Member Functions | List of all members
libcamera::SharedMem Class Reference

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...
 
SharedMemoperator= (SharedMem &&rhs)
 Move constructor for SharedMem. More...
 
const SharedFDfd () const
 Gets the file descriptor for the underlaying shared memory. More...
 
void * mem () const
 Gets the pointer to the underlaying shared memory. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ SharedMem() [1/2]

libcamera::SharedMem::SharedMem ( const std::string &  name,
std::size_t  size 
)

Contstructor for the SharedMem.

Parameters
[in]nameName of the SharedMem
[in]sizeSize of the shared memory to allocate and map

◆ SharedMem() [2/2]

libcamera::SharedMem::SharedMem ( SharedMem &&  rhs)
inline

Move constructor for SharedMem.

Parameters
[in]rhsThe object to move

◆ ~SharedMem()

libcamera::SharedMem::~SharedMem ( )
inline

SharedMem destructor.

Unmaps the allocated shared memory. Decrements the shared memory descriptor use count.

Member Function Documentation

◆ fd()

const SharedFD & libcamera::SharedMem::fd ( ) const
inline

Gets the file descriptor for the underlaying shared memory.

Returns
The file descriptor

◆ mem()

void * libcamera::SharedMem::mem ( ) const
inline

Gets the pointer to the underlaying shared memory.

Returns
The pointer to the shared memory

◆ operator=()

SharedMem & libcamera::SharedMem::operator= ( SharedMem &&  rhs)
inline

Move constructor for SharedMem.

Parameters
[in]rhsThe object to move

The documentation for this class was generated from the following files: