C:\Users\igaztanaga\Desktop\kk\a C:\Users\igaztanaga\Desktop\kk\b
#include·<boost/interprocess/managed_shared_memory.hpp>¤ #include·<boost/interprocess/managed_shared_memory.hpp>¤
#include·<boost/interprocess/allocators/allocator.hpp>¤ #include·<boost/interprocess/allocators/allocator.hpp>¤
#include·<boost/interprocess/containers/map.hpp>¤ #include·<boost/interprocess/containers/map.hpp>¤
#include·<boost/interprocess/containers/vector.hpp>¤ #include·<boost/interprocess/containers/vector.hpp>¤
#include·<boost/interprocess/containers/string.hpp>¤ #include·<boost/interprocess/containers/string.hpp>¤
¤ ¤
using·namespace·boost::interprocess;¤ using·namespace·boost::interprocess;¤
¤ ¤
//Typedefs·of·allocators·and·containers¤ //Typedefs·of·allocators·and·containers¤
typedef·managed_shared_memory::segment_manager·····segment_manager_t;¤ typedef·managed_shared_memory::segment_manager·····segment_manager_t;¤
typedef·allocator<void,·segment_manager_t>·························void_allocator;¤ typedef·allocator<void,·segment_manager_t>·························void_allocator;¤
typedef·allocator<int,·segment_manager_t>····························int_allocator;¤ typedef·allocator<int,·segment_manager_t>····························int_allocator;¤
typedef·vector<int,·int_allocator>·················································int_vector;¤ typedef·vector<int,·int_allocator>·················································int_vector;¤
typedef·allocator<int_vector,·segment_manager_t>···············int_vector_allocator;¤ typedef·allocator<int_vector,·segment_manager_t>···············int_vector_allocator;¤
typedef·vector<int_vector,·int_vector_allocator>························int_vector_vector;¤ typedef·vector<int_vector,·int_vector_allocator>························int_vector_vector;¤
typedef·allocator<char,·segment_manager_t>·························char_allocator;¤ typedef·allocator<char,·segment_manager_t>·························char_allocator;¤
typedef·basic_string<char,·std::char_traits<char>,·char_allocator>···char_string;¤ typedef·basic_string<char,·std::char_traits<char>,·char_allocator>···char_string;¤
typedef·vector<char_string,·char_allocator>··························char_string_vector_vector;¤ typedef·allocator<char_string,·segment_manager_t>····················char_string_allocator;¤
  typedef·vector<char_string,·char_string_allocator>···················char_string_vector_vector;¤ 
¤ ¤
class·complex_data¤ class·complex_data¤
public:·//Obviously·making·the·variables·of·complex_data·public·isn't·good·idea·am·just·playing·here·for·the·moment¤ public:·//Obviously·making·the·variables·of·complex_data·public·isn't·good·idea·am·just·playing·here·for·the·moment¤
···int························id_;¤ ···int························id_;¤
···char_string·······char_string_;¤ ···char_string·······char_string_;¤
···char_string_vector_vector·char_string_vector_vector_;¤ ···char_string_vector_vector·char_string_vector_vector_;¤
···double·price_;¤ ···double·price_;¤
···//Since·void_allocator·is·convertible·to·any·other·allocator<T>,·we·simplify¤ ···//Since·void_allocator·is·convertible·to·any·other·allocator<T>,·we·simplify¤
···//the·initialization·taking·just·one·allocator·for·all·inner·containers.¤ ···//the·initialization·taking·just·one·allocator·for·all·inner·containers.¤
···complex_data(int·id,·const·char·*name,·double·prce,·const·void_allocator·&void_alloc)¤ ···complex_data(int·id,·const·char·*name,·double·prce,·const·void_allocator·&void_alloc)¤
······id_(id),·char_string_(name,·void_alloc),·char_string_vector_vector_(void_alloc),·price_(prce)¤ ······id_(id),·char_string_(name,·void_alloc),·char_string_vector_vector_(void_alloc),·price_(prce)¤
···{}¤ ···{}¤
¤ ¤
···//·add·string·-->·Error·is·on·the·next·line¤ ···//·add·string·-->·Error·is·on·the·next·line¤
···void·addStringItem(char_string*·s){char_string_vector_vector_.push_back(s);}¤ ···void·addStringItem(char_string*·s){char_string_vector_vector_.push_back(*s);}¤
  ¤ 
  ···void·addStringItem(const·char*·s)¤ 
  ··· 
  ······//Every·time·you·build·from·raw·string·you·need·an·allocator¤ 
  ······//in·the·constructor¤ 
  ······char_allocator·alloc(char_string_vector_vector_.get_allocator());¤ 
  ······char_string_vector_vector_.push_back(char_string(s,·alloc));¤ 
  ··· 
};¤ };¤
¤ ¤
int·main·()¤ int·main·()¤
···//Remove·shared·memory·on·construction·and·destruction¤ ···//Remove·shared·memory·on·construction·and·destruction¤
···struct·shm_remove¤ ···struct·shm_remove¤
··· ···
······shm_remove()·shared_memory_object::remove("MySharedMemory");· ······shm_remove()·shared_memory_object::remove("MySharedMemory");·
······~shm_remove(){·shared_memory_object::remove("MySharedMemory");· ······~shm_remove(){·shared_memory_object::remove("MySharedMemory");·
···remover;¤ ···remover;¤
¤ ¤
···//Create·shared·memory¤ ···//Create·shared·memory¤
···managed_shared_memory·segment(create_only,"MySharedMemory",·65536);¤ ···managed_shared_memory·segment(create_only,"MySharedMemory",·65536);¤
¤ ¤
···//An·allocator·convertible·to·any·allocator<T,·segment_manager_t>·type¤ ···//An·allocator·convertible·to·any·allocator<T,·segment_manager_t>·type¤
···void_allocator·alloc_inst·(segment.get_segment_manager());¤ ···void_allocator·alloc_inst·(segment.get_segment_manager());¤
¤ ¤
···//Construct·the·shared·memory·map·and·fill·it¤ ···//Construct·the·shared·memory·map·and·fill·it¤
···complex_data·*mymap·segment.construct<complex_data>("Complex_Data")(7,·"hi",·7.0,·alloc_inst);¤ ···complex_data·*mymap·segment.construct<complex_data>("Complex_Data")(7,·"hi",·7.0,·alloc_inst);¤
  ···mymap->addStringItem("hello");¤ 
¤ ¤
···//¤ ···//¤
···return·0;¤ ···return·0;¤