Class shared_memory::SharedMemorySegment¶
-
class shared_memory::SharedMemorySegment¶
The SharedMemorySegment contains the pointers of the shared objects in on shared memrory segment.
We use unamed mutext (interprocess_mutex) and unamed condition variables (interprocess_condition) to be able to instanciate them with classic pointers
Public Functions
-
SharedMemorySegment(std::string segment_id, bool clear_upon_destruction, bool create)¶
SharedMemorySegment constructor.
-
inline ~SharedMemorySegment()¶
SharedMemorySegment destructor.
-
void clear_memory()¶
clear_memory free the shared memory
-
template<typename ElemType>
void get_object(const std::string &object_id, std::pair<ElemType*, std::size_t> &get_)¶ get_object registers the object in the current struc and in the shared memory once only.
And returns the pointer to the object and its size. The size will be 1 for simple type and could greater to one for arrays.
- Parameters
object_id – [in] the name of the object in the shared memory.
- Param
-
void get_object(const std::string &object_id, std::string &get_)¶
get_object registers the object in the current struc and in the shared memory once only.
And returns the pointer to the object and its size. The size will be 1 for simple type and could greater to one for arrays.
- Parameters
object_id – [in] the name of the object in the shared memory.
- Param
-
template<typename ElemType>
void set_object(const std::string &object_id, const std::pair<const ElemType*, std::size_t> &set_)¶ set_object registers the object in the current struc and in the shared memory once only.
And returns the pointer to the object and its size. The size will be 1 for simple type and could greater to one for arrays.
- Parameters
object_id – [in] the name of the object in the shared memory.
set_ – [in] the reference to the fetched object.
-
template<typename ElemType>
bool register_object(const std::string &object_id, const std::pair<ElemType*, std::size_t> &obj_)¶ register_object registers the object in the segment uniquely.
- Parameters
object_id – is the name of the object to register.
obj_ – is the object to be registered.
- Returns
true of a new object has been registered
-
template<typename ElemType>
bool register_object_read_only(const std::string &object_id)¶ register_object_read_only registers the object in the segment uniquely.
- Parameters
object_id – is the name of the object to register
obj_ – is the object to be registered
- Returns
true of a new object has been registered
-
template<typename ElemType>
void delete_object(const std::string &object_id)¶ delete_object delete and object from the shared memory.
- Parameters
object_id – [in] the name of the object in the shared memory.
-
inline void create_mutex()¶
create_mutex small factory that allow to make sure that the mutex is created.
-
inline void destroy_mutex()¶
destroy_mutex small destructor of the mutext to make sure that it is unlock at critical time.
-
inline bool is_object_registered(const std::string &object_id)¶
is_object_registered used to check if the object has been registered or not.
- Parameters
object_id – [in] the name of the object in the shared memory.
- Returns
true if it has been registered
-
inline void set_clear_upon_destruction(const bool clear_upon_destruction)¶
set_clear_upon_destruction is a standard setter
- Parameters
clear_upon_destruction – [in] is the value to set
-
inline const std::string &get_segment_id()¶
get_segment_id is a standard getter
- Returns
the segment name
-
inline SegmentInfo get_info()¶
performs introspection on the segment and return related information
Public Members
-
boost::interprocess::interprocess_mutex *mutex_¶
mutex_ this mutex secure ALL the shared memory.
Private Members
-
boost::interprocess::managed_shared_memory segment_manager_¶
shm_segment is the boost object that manages the shared memory segment
-
ShmObjects objects_¶
objects_ are all the data stored in the segment.
WARNING here we use void* so the use of the set and get functions is the RESPONSABILITY of the user.
The user is to use the SAME type when calling set and get using the shared memory
-
std::string segment_id_¶
segment_id_ is the name of the segment inside the shared memory
-
bool clear_upon_destruction_¶
clear_upon_destruction_ flag decides if the segment should be cleared upon destruction.
Usage: typically only one process should set this flag to true.
-
int ravioli_¶
-
SharedMemorySegment(std::string segment_id, bool clear_upon_destruction, bool create)¶