File shared_memory.hxx¶
This file implements the functions from shared_memory.hpp that encapsulate the use of the shared memory using the boost::interprocess package. usage: see demos and unit tests and documentation.
- License:
License BSD-3-Clause
- Author
Vincent Berenz
- Author
Maximilien Naveau (maximilien.naveau@gmail.com)
- Copyright
Copyright (c) 2019, New York University and Max Planck Gesellschaft.
- Date
2019-05-22
-
namespace shared_memory
All templated types in this namespaces are elementary types: int, double, float, char*, …
Typedefs
-
typedef std::map<std::string, std::unique_ptr<SharedMemorySegment>> SegmentMap¶
SegmentMap typedef is a simple short cut to the GLOBAL_SHM_SEGMENTS type.
Functions
-
template<typename ElemType>
bool delete_object(const std::string &segment_id, const std::string &object_id)¶ delete_object deletes a particular object in the shared memory segment
- Parameters
segment_id – [in] is the name of the shared memory segment.
- Returns
true if everything went fine.
-
template<typename ElemType>
void set(const std::string &segment_id, const std::string &object_id, const ElemType &set_)¶ set instanciates or get pointer to any elementary types in the shared memory.
All set functions make sure that the pointer is uniquely created to avoid useless computation time consumption.
- Parameters
segment_id – [in] is the name of the shared memory segment.
object_id – [in] is the name of the shared memory object to set.
set_ – [in] is the string to be created in the shared memory
-
template<typename ElemType>
void set(const std::string &segment_id, const std::string &object_id, const ElemType *set_, const std::size_t size)¶ set instanciates or get pointer to a fixed sized array of the templated type “T” in the shared memory.
All set functions make sure that the pointer is uniquely created to avoid useless computation time consumption.
- Parameters
segment_id – [in] is the name of the shared memory segment.
object_id – [in] is the name of the shared memory object to set.
set_ – [in] is the pointer to the array of objects to set in the memory.
size – [in] is the array size.
-
template<typename ElemType>
void set(const std::string &segment_id, const std::string &object_id, const std::vector<ElemType> &set_)¶ set instanciates or get pointer to a std::vector<ElemType> in the shared memory.
This will translated as a fixed sized array in the shared memory
All set functions make sure that the pointer is uniquely created to avoid useless computation time consumption.
- Parameters
segment_id – [in] is the name of the shared memory segment.
object_id – [in] is the name of the shared memory object to set.
set_ – [in] is the string to be created in the shared memory
-
template<typename ElemType>
void set(const std::string &segment_id, const std::string &object_id, const Eigen::Matrix<ElemType, Eigen::Dynamic, 1> &set_)¶ set instanciates or get pointer to a Eigen::Matrix<ElemType, Eigen::Dynamic, 1> in the shared memory.
This will translated as a fixed sized array in the shared memory
All set functions make sure that the pointer is uniquely created to avoid useless computation time consumption.
- Parameters
segment_id – [in] is the name of the shared memory segment.
object_id – [in] is the name of the shared memory object to set.
set_ – [in] is the string to be created in the shared memory
-
template<typename FirstType, typename SecondType>
void set(const std::string &segment_id, const std::string &object_id, const std::pair<FirstType, SecondType> &set_)¶ set instanciates or get pointer to a std::pair<FirstType, SecondType> in the shared memory.
This is very usefull to dump maps in the shared memory
All set functions make sure that the pointer is uniquely created to avoid useless computation time consumption.
- Parameters
segment_id – [in] is the name of the shared memory segment.
object_id – [in] is the name of the shared memory object to set.
set_ – [in] is the string to be created in the shared memory
-
template<typename KeyType, typename ValueType>
void set(const std::string &segment_id, const std::string &object_id, const std::map<KeyType, ValueType> &set_)¶ set instanciates or get pointer to a std::vector<ElemType> or an Eigen::Matrix<ElemType, any, any> in the shared memory.
This will translated as a fixed sized array in the shared memory
All set functions make sure that the pointer is uniquely created to avoid useless computation time consumption.
- Parameters
segment_id – [in] is the name of the shared memory segment.
object_id – [in] is the name of the shared memory object to set.
set_ – [in] is the string to be created in the shared memory
-
template<typename ElemType>
void get(const std::string &segment_id, const std::string &object_id, ElemType &get_, bool create = true)¶ get gets a pointer to any elementary types in the shared memory.
All set functions make sure that the pointer is uniquely created to avoid useless computation time consumption.
- Parameters
segment_id – [in] is the name of the shared memory segment.
object_id – [in] is the name of the shared memory object to set.
get_ – [in] is the string to be created in the shared memory
-
template<typename ElemType>
void get(const std::string &segment_id, const std::string &object_id, ElemType *get_, const std::size_t expected_size, bool create = true)¶ get gets a pointer to a fixed sized array of the templated type “T” in the shared memory.
All set functions make sure that the pointer is uniquely created to avoid useless computation time consumption.
- Parameters
segment_id – [in] is the name of the shared memory segment.
object_id – [in] is the name of the shared memory object to set.
get_ – [in] is the pointer to the array of objects to set in the memory.
size – [in] is the array size.
create – [in] : if false, raise a Non_existing_segment_exception if the segment does not already exist
-
template<typename ElemType>
void get(const std::string &segment_id, const std::string &object_id, std::vector<ElemType> &get_, bool create = true)¶ get gets a pointer to a std::vector<ElemType> in the shared memory.
This will translated as a fixed sized array in the shared memory
All set functions make sure that the pointer is uniquely created to avoid useless computation time consumption.
- Parameters
segment_id – [in] is the name of the shared memory segment.
object_id – [in] is the name of the shared memory object to set.
set_ – [in] is the string to be created in the shared memory
create – [in] : if false, raise a Non_existing_segment_exception if the segment does not already exist
-
template<typename ElemType>
void get(const std::string &segment_id, const std::string &object_id, Eigen::Matrix<ElemType, Eigen::Dynamic, 1> &get_, bool create = true)¶ get gets a pointer to a Eigen::Matrix<ElemType, Eigen::Dynamic, 1> in the shared memory.
This will translated as a fixed sized array in the shared memory
All set functions make sure that the pointer is uniquely created to avoid useless computation time consumption.
- Parameters
segment_id – [in] is the name of the shared memory segment.
object_id – [in] is the name of the shared memory object to set.
set_ – [in] is the string to be created in the shared memory
create – [in] : if false, raise a Non_existing_segment_exception if the segment does not already exist
-
template<typename FirstType, typename SecondType>
void get(const std::string &segment_id, const std::string &object_id, std::pair<FirstType, SecondType> &get_, bool create = true)¶ get instanciates or get pointer to a std::pair<FirstType, SecondType> in the shared memory.
This is very usefull to dump maps in the shared memory
All set functions make sure that the pointer is uniquely created to avoid useless computation time consumption.
- Parameters
segment_id – [in] is the name of the shared memory segment.
object_id – [in] is the name of the shared memory object to set.
get_ – [in] is the string to be created in the shared memory
create – [in] : if false, raise a Non_existing_segment_exception if the segment does not already exist
-
template<typename KeyType, typename ValueType>
void get(const std::string &segment_id, const std::string &object_id, std::map<KeyType, ValueType> &get_, bool create = true)¶ get gets a pointer to a std::vector<ElemType> or an Eigen::Matrix<ElemType, any, any> in the shared memory.
This will translated as a fixed sized array in the shared memory
All set functions make sure that the pointer is uniquely created to avoid useless computation time consumption.
- Parameters
segment_id – [in] is the name of the shared memory segment.
object_id – [in] is the name of the shared memory object to set.
get_ – [in] is the string to be created in the shared memory
create – [in] : if false, raise a Non_existing_segment_exception if the segment does not already exist
-
template<typename VectorType, typename ElemType>
void set(const std::string &segment_id, const std::string &object_id, const VectorType &set_)¶
Variables
-
bool VERBOSE¶
-
static SegmentMap GLOBAL_SHM_SEGMENTS¶
GLOBAL_SHARED_MEMORY_SEGMENT is global variable that acts as a a shared memory manager.
The use of the std::unique_ptr allows to delete the object and re-create at will.
-
typedef std::map<std::string, std::unique_ptr<SharedMemorySegment>> SegmentMap¶