Transfer variable-size data using shared memory

4 posts / 0 new
Last post
Offline
Last seen: 9 months 2 days ago
Joined: 03/28/2024
Posts: 2
Transfer variable-size data using shared memory

described in documentation:

Identify types that require Zero Copy transfer over shared memory and annotate them with @transfer_mode(SHMEM_REF) in the IDL files.

 Zero Copy transfer over shared memory requires the FlatData language binding when the type is variable-size.

So, if  transfer variable-size data using shared memory, I need add @mutable。rti::flat::build_data(writer) will be used。

 

but, this sentence: Use the DataWriter’s get_loan() API to get a loaned sample for writing with Zero Copy。

 

my question:the conflict between rti::flat::build_data(writer) and get_loan(). Which method is used to structure the data?

Organization:
Howard's picture
Offline
Last seen: 1 week 2 days ago
Joined: 11/29/2012
Posts: 618

In the case that your data type is

@mutable
@language_binding(FLAT_DATA)

Then, you should use

rti::flat::build_data(writer)

to get the Builder object that you will use to populate the data sample/structure.  You would not use the DataWriter::get_loan() API.  The build_data() will return an object that internally has the loaned shared memory segment that it got from the DataWriter.

 

Offline
Last seen: 9 months 2 days ago
Joined: 03/28/2024
Posts: 2

Thank you very much for your reply!

for example:

module test_types {
@mutable
@transfer_mode(SHMEM_REF)
@language_binding(FLAT_DATA)
struct CameraImage {
int64 timestamp;
string<128> test_string;
sequence<int32, 128> test_seq;
};
};

Transfer variable-size data using shared memory,based on your reply:
In addition to adding @mutable, and @language_binding(FLAT_DATA), do I need to add @transfer_mode(SHMEM_REF) ?  why?

 

Howard's picture
Offline
Last seen: 1 week 2 days ago
Joined: 11/29/2012
Posts: 618

If you want to transfer that data structure using Zero Copy then you need to have the @transfer_mode(SHMEM_REF).

The @mutable and @language_binding(FLAT_DATA) is only additionally needed when the data structure has variable sized members.