I am looking for a way to send class object from one process to another.
For example assuming I have a class
class my_class
{
public:
my_class_variable;
my_class() { my_class_variable = 0; }
};
My main forks a child that child works on an object of class "my_class"
int main()
{
my_class my_class_obj = new my_class;
if (fork() == 0)
{
my_class_obj.my_class_variable = 1;
exit(0);
}
else
{
wait(NULL);
my_class new_obj = new my_class;
//how do I copy the "my_class_obj" into new_obj
}
}
This is a rather simple example for the sake of just this example I could just use a pipe and send the value '1' through that pipe. But I am stuck in a scenario where I have class with more than 7 variables that a child process updates.
Now I have noticed that when I exit the child process the instance of class on which child process was working is destroyed (regardless of the fact that the object instance was initialized in the parent and not inside the child). So now I cannot retrieve the values that were updated by the child process on that class object. Accessing member variables of that class outside child process only gives default values not the values that were set by child process.
I have thought of using pipes but how would I implement that and send a class object inside a pipe, because currently I only know how to send integer and string variables through pipes.
Please help how can I transfer class objects instances from one process to another.