Sunday 15 July 2012

stdstring - Using Boost flyweight with shared memory -


I want to put a large number of (often duplicate) strings in shared memory, so I'm using Boost Floyd and Interprosures Basic_String Functionality To ensure that the string is actually stored in shared memory, I need to provide a custom allocator in the fast-moving handheascript.

However, it fails to compile (G ++ 4.2.1) when I specify my custom allocate for the head_netter ... possibly because the additional argument for specifying the segment manager What is the syntax for doing this job, or what is the best way to do this?

  #include & lt; Boost / interprocess / managed_mapped_file.hpp & gt; #include & lt; Boost / interprocess / managed_shared_memory.hpp & gt; # Include & lt; Promotion / Interpresence / Allocation / Recurrent HP & gt; #include & lt; Boost / interprocess / containers / string.hpp & gt; # Include & lt; Boost / flyweight.hpp & gt; #include & lt; Boost / flyweight / no_tracking.hpp & gt; #include & lt; Boost / flyweight / hashed_factory.hpp & gt; Promotion of namespace: using flywheats; Promotion of namespace: using container; Namespace Promotion: Using Interprosession; Typedef boost :: interprocess :: allocation & lt; Promotion :: Emple :: _ 1, Promotion :: interprocess :: managed_mapped_file :: segment_manager & gt; ShmFactoryEntryAllocator; Typedef boost :: interprocess :: excise & lt; Char, boost :: interprocess :: managed_mapped_file :: segment_manager & gt; ShmAllocatorChar; Typedef boost :: interprocess :: basic_string & lt; Char, std :: char_traits & lt; Char & gt ;, ShmAllocatorcher & gt; ShmString; // TODO: typedef boost using ShmFactoryEntryAllocator :: flyweights :: hashed_factory & lt; Boost :: hash & lt; Shmstring & gt; Std :: equal_to & lt; Shmstring>, shmfactoryEntryAllocator & gt; ShmStringHashedFactory; // Typing Boost: FlyWeight :: Hash_Taceter & lt; Boost :: hash & lt; Shmstring & gt; Std :: equal_to & lt; Shmstring & gt; std :: allocation & lt; Boost :: mpl :: _ 1 & gt; & Gt; ShmStringHashedFactory; // TODO: Need to be able to use hashed_factory with our custom allocated typefed boost: flywheatts :: flyweight and lieutenant; SMR string, SMR stringHashifyFactor & gt; ShmFlyweightString; // Tide Prom Boost :: Flyweight :: Flyweight and Lieutenant; SMR string & gt; ShmFlyweightString; Int main (int argc, char ** argv) {managed_mapped_file * segment = new managed_mapped_file (create_only, "memory.dat", 409600); ShmFactoryEntryAllocator FactoryInternational Allocator (Segment-> get_segment_manager ()); // Create a normal string in the shared memory ShmString * ps1 = section-> Create & lt; ShmString & gt; ("S1") ("some shm general string", factoryinteri allocator); // Create a flyweight string in the shared memory ShmFlyweightString * ps2 = section-> Create & lt; ShmFlyweightString & gt; (Anonymous_sthan) ("Some Schmidt Flyweight String", Factory Entrepreneur All); Return 0; }   

Lines after the Todo observations are problematic lines, they work with commented versions but do not use the correct allocation.

It seems that you are the reason for having the right constructor logic of the problem. Says:

The built-in hashed container on which hashed_factory_class is based on hash, is designed with default starting objects of headmaster and allocation.

I am surprised that you can work on the basis of a sub-section of shared memory allocation around which is the default constructor, passing through the Segment Manager for the base class constructor. is. For example, something like this:

  class MyShmAllocator: Public ShmFactoryEntryAllocator {Public: Stable Boost: interprocess :: managed_mapped_file :: segment_manager * segmentManager; MyShmAllocator (): ShmFactoryEntryAllocator (* Segment Manager) {}};   

You will need to assign a "current" MyShmAllocator :: segmentManager to any constructor before any call. It's a bit ugly but I think it should work.

No comments:

Post a Comment