Sharing a complex object between two processes: Suggestions needed

Thanks so much for a great C++ library, Last night I read the complete archive looking for some tidbits of info to help me figure out how to move forward with a decision of the appropriate approach. I am fairly new to boost so I am hoping someone has some advice for my situation. I am trying to share instances of a c++ class that is auto-generated from xml schema. I am trying to hand this class off from a dll that a web service engine loads to another application for processing. This class is an in-memory implementation of the class and contains several objects which contain a lot of native stl c++ strings as well as other primitive types. I was hoping to use boosts circular buffer in shared memory, but began prototyping with a vector it and researching and I realized that the strings put in shared memory must use the basic_string construct. Having some concern about going through all of the auto generated code to change all of these types and concern over what affect that might have on the dll & service engine operation. I've seen some examples using shared memory that use the void allocator and thought maybe that is what I need to do, however I keep getting back to the fact that I've got a bunch of strings in this composite class and I don't know if that is torpedoing my attempts. I've seen there are many interprocess constructs, memory mapped regions, shared_ptrs and message ques etc. I also recently got to thinking that perhaps I should look at boost serialize to deal with the strings. I didn't want to leave the boost interprocess approach if there was some way to exchange instances of this class correctly using one of boost interprocess constructs. What I am hoping is that some could chime in with suggestions on different ways to use boost to achieve this and I'll try and go off and research it. Your input is greatly appreciated!

On Tue, 12 Jul 2011 23:12:30 +0200, Nathan Lewis
I am trying to share instances of a c++ class that is auto-generated from xml schema. I am trying to hand this class off from a dll that a web service engine loads to another application for processing.
Maybe offtopic, but the keywords like web services, xml and serialization sounds like Java appliance area for me, rather than C/C++.

Yes this was not my idea. However the back end devices are low level devices without Java sdks. I have taken over a project whereby they were using Java, JNI & C++ which apparently isn't working out so well. I was asked to create a prototype using c++ instead. Any thoughts on my actual question though?

On Wed, Jul 13, 2011 at 1:05 PM, Nathan Lewis < nathanlewissubscription@gmail.com> wrote:
Yes this was not my idea. However the back end devices are low level devices without Java sdks. I have taken over a project whereby they were using Java, JNI & C++ which apparently isn't working out so well. I was asked to create a prototype using c++ instead.
Any thoughts on my actual question though?
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
If I was going to go with a C++ shared memory situation, I would start with a shared memory region and use the library to allocate memory within that mapped region. Check out segment_manager and any_interprocess_allocator: they would be extremely useful if you take this route ( http://www.boost.org/doc/libs/1_47_0/doc/html/interprocess/allocators_contai...). You'll have to be *extremely* careful that all of your containers and all of your objects use the instanced allocators. If they don't and you end up with a default allocator for some shared object, you will get a segmentation fault in the best case and inconsistent data in the worst. It might not be possible to do if you don't have control over your generator (since you'll have to change the Allocator typename in all the container types). Personally, I would go with the Boost.Asio library and transfer data between processes explicitly over a named pipe (Boost.Serialization or do it with JSON). This way, you won't get any funky my-memory-was-changed-by-another-process action, which will make debugging a million times easier. The first option is going to be *way* easier to create if you can make your code generator do it for you, but you have to be *extremely* careful about your type definitions. The second option might a little tedious for some of the serialization, but should be easier to debug. -- - Travis Gockel
participants (3)
-
Nathan Lewis
-
Travis Gockel
-
Viatcheslav.Sysoltsev@h-d-gmbh.de