jeudi 20 avril 2017

I transferred a std::pair over a named pipe how did it work?

I passed a std::pair over a named pipe using read() and write() functions in Linux. I passed it by reference, and read it by reference. How did that work? From what I know, std::pair is not serialized and what happens when the reference goes out of scope. Can an object be moved, or a copy by reference?

I am confused.

I am new to C++, so my pointer and reference knowledge is a little poor, but from what I know I am passing the address over the pipe and then pointing the read side object to this new address.

Though the read side object is, well, an object, not a pointer. So what happens to it's old/original instance?

I am writing using this code:

std::pair<int, somestruct> sample_pair;
write(FD, &sample_pair, sizeof(sample_pair));

And reading it using this code:

std::pair<int, somestruct> sample_pair;
read(FD, &sample_pair, sizeof(sample_pair));

Aucun commentaire:

Enregistrer un commentaire