Closed afpgit closed 9 months ago
@afpgit This is expected. The types you are allowed to use in zero-copy communication must satisfy multiple properties:
The string violates 1. and 3. But no worries, you can use the iox::string
as alternative, then your code would look like:
#include "iox/string.hpp"
struct RadarObjectWithString {
double x = 0.0;
double y = 0.0;
double z = 0.0;
iox::string<128> s("string"); // creates a fixed size string with the maximum capacity of 128
};
The reason why you have to satisfy strictly the requirements is, that every process has its own local process space that cannot be accessed from within another process. So if your data structure uses the heap, this heap address is not accessible from another process which causes a segfault.
If you use vtables those tables are essentially function pointer that are also no longer valid in another process space.
And if your construct is using pointers internally, those pointers are invalidated in another process space due to the address randomization. For instance in process A
the process space goes from 0x10 ... 0x2020 and in process B from 0xbebe ... 0xcafe
so if the pointer in process A is pointing to memory location 0x12 it is valid only for process A, in process B it would point to an invalid memory address.
@afpgit You can find the above info and much more also in the official documentation: https://iceoryx.io/latest/getting-started/overview/#restrictions. A good read is about shared memory which visualizes what @elfenpiff described can be found here: https://github.com/eclipse-iceoryx/iceoryx/blob/v2.0.5/doc/shared-memory-communication.md
Closing the issue. elfenpiff and mossmaurice already answered the question.
Required information
Operating system: CentoOS7 / Windows 11
Compiler version: GCC 11.2.1, VS2022 Community
Eclipse iceoryx version: v2.0.3
Observed result or behaviour: Subscriber crashes in CentOS7 with segmentation fault. Subscriber works successfully in Windows.
Conditions where it occurred / Performed steps: Just modified the publisher/subscriber examples in the
iceoryx/iceoryx_examples/icehello/
folder from:to:
This
std::string
addition to the data causes asegmentation fault
in CentOS7 when I try to read the string data in the subscriber usingtakeResult.value()->s
. The value ofx
,y
,z
are still perfectly accessible in CentOS7 usingtakeResult.value()->x
, ... .However, the same code works successfully in Windows and I can print the value of
s
usingtakeResult.value()->s
as well as the rest of the struct members.