I open file by SimGrid framework:
msg_file_t file = MSG_file_open("/scratch/bin/tesh", NULL);
XBT_INFO("file size is %zd", MSG_file_get_size(file));
It's OK:
[carl:host:(1) 0.000000] [remote_io/INFO] file size is 356434
Then I want to set some data to this file. Firstly, I create typedef structure:
typedef struct {
char* number_used;
}data, *dataPtr;
Then I set data with MSG_file_set_data
to this file:
dataPtr data_1 = xbt_new(data, 1);
data_1->number_used = xbt_strdup("1");
MSG_file_set_data(file, data);
But after closing file I can't get the value of data_1->number_used
:
file = MSG_file_open("/scratch/bin/tesh", NULL);
dataPtr data_2 = MSG_file_get_data(file);
XBT_INFO("number used %s", data_2->number_used);
It gives segmentation fault
and value of data_2
is null
. What did I do wrong?
A msg_file_t object only exists between the MSG_file_open and MSG_file_close calls. Calling again MSG_file_open on the same file name creates a new msg_file_t object (a new descriptor). Then user data attached to a msg_file_t are not persistent across multiple open/close on a file name.