I have a process that internally makes "std::system" call. (I believe system call spawns a child process). In the system call, I am executing different application as
void generate()
{
std::system("./childProcess.exe);
}
The above "generate function" would be called by multiple threads. Now, I need to share a "complex object" from Parent process to child process, i.e., childProcess.exe.
I tried with Boost::interprocess::shared_memory but in vain.
The complex object i mentioned earlier internally dynamically allocates memory many a times. I believe those dynamically allocated memories are not associated with my shared memory segment. Please correct me if otherwise
My class is like this
Complex compClass
{
int cnt;
subclass *subobj;
}
compClass::compClass()
{
subobj=new subclass;
subobj->func;
}
subclass::func()
{
YClass *y = new YClass;
}
and so on, it internally has many such memory allocations.
When I create a shared memory segment of object type "Comp class" in parent process, and open the shared memory segment in child process, i am able to access "cnt" variable in child process. But, I am not able to access subobject in child process.
I believe this is because subobject is dynamically allocated and we have different dynamic memory allocated in child processes and they are not associated with shared memory segment.
I found even for std::string, boost comes up with boost::interprocess::string as string internally makes "new" call.
Please suggest the best IPC mechanism to share this "Complex object" between multiple processes.
boost::interprocess::stringis just an alias forboost::containers::stringIIRC. The important thing is to use an allocator to allocate from the shared memory segment manager, AFAIR - sehe