#include #include #include #include #include #include #include using namespace boost::flyweights; using namespace boost::container; using namespace boost::interprocess; typedef boost::interprocess::allocator ShmFactoryEntryAllocator; typedef boost::interprocess::allocator ShmAllocatorChar; typedef boost::interprocess::basic_string, ShmAllocatorChar> ShmString; // TODO: using ShmFactoryEntryAllocator does not work typedef boost::flyweights::hashed_factory, std::equal_to, ShmFactoryEntryAllocator> ShmStringHashedFactory; //typedef boost::flyweights::hashed_factory, std::equal_to, std::allocator > ShmStringHashedFactory; // TODO: need to be able to use a hashed_factory with our custom allocator. //typedef boost::flyweights::flyweight ShmFlyweightString; typedef boost::flyweights::flyweight ShmFlyweightString; // --------------- int main(int argc, char** argv) { managed_mapped_file *segment = new managed_mapped_file(create_only, "memory.dat", 409600); ShmFactoryEntryAllocator factoryEntryAllocator(segment->get_segment_manager()); // create a normal string in shared memory. //ShmString s1("some shm normal string", factoryEntryAllocator); // create a normal string in shared-memory, including the class itself. ShmString *ps1 = segment->construct("s1")("some shm normal string", factoryEntryAllocator); printf("ps1 = %p\n", ps1->c_str()); // create a flyweight string in shared memory. //ShmFlyweightString s2("some shm flyweight string", factoryEntryAllocator); // create a flyweight string in shared memory, including the class itself. ShmFlyweightString *ps2 = segment->construct(anonymous_instance)("some shm flyweight string", factoryEntryAllocator); printf("ps2 = %p\n", ps2->get().c_str()); return 0; }