Roma  Karageorgievich Roma Karageorgievich - 11 months ago 50
C++ Question

How to create a process with vector in SimGrid?

I want to create a process with data in SimGrid, so I do this:

int worker(int argc, char *argv[])
vector<string> vector1;
MSG_process_create("x", executor, &vector1, MSG_host_self());
return 0;

But in
I have a segmentation error:

int executor(int argc, char* argv[]){
vector<string> *data = (vector<string>*) MSG_process_get_data(MSG_process_self());
XBT_INFO("%s", data->front().c_str());
return 0;

I know that it happened because
goes out of scope when
function ends and
dissappered, so "there is no vector1 data" in executor.

How to do it properly?

Answer Source

I think you just want to use a pointer here :)

int worker(int argc, char *argv[]) { vector<string>* vector1 = new vector<string>(); vector1->push_back("word"); MSG_process_create("x", executor, vector1, MSG_host_self()); free(vector1); return 0; }