eclipse-iceoryx / eclipse-iceoryx/iceoryx2
Proposal: use rust Layout to calculate Sample Layout
- Dominant language
- Rust
- Stars
- 2.5k
- Forks
- 185
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 47
Description
Method `sample_layout` calculates the layout by appending and call functions with unsafe.
https://github.com/eclipse-iceoryx/iceoryx2/blob/ca22976c4bce5f9b92c53e3a0e1571ad9d8a086d/iceoryx2/src/service/static_config/message_type_details.rs#L104-L118
I'm not sure why we use this approach to calculate layout(probably to keep the same with iceoryx in c++). I found we can rely on rust to calculate the layout as if we define a structure for the whole sample. Hence, `sample_layout_genric::(2)` works as if we define a structure `S1`:
```rust
#[repr(C)]
struct S1 {
_a: i32,
_user_header: bool,
_layout: [i64; 2],
}
```
The sample_layout_genric is shown below:
```rust
pub(crate) fn sample_layout_genric(&self, n: usize) -> Layout {
let layout_header = Layout::new::();
let layout_user_header = Layout::new::();
let layout_array = Layout::array::(n).ok().unwrap();
layout_header
.extend(layout_user_header)
.ok()
.unwrap()
.0
.extend(layout_array)
.ok()
.unwrap()
.0
.pad_to_align()
}
```
I have the committed the [change](https://github.com/xieyuschen/iceoryx2/commit/d40956c02283626f9cdc6913bc77c39d9f5f373a) for you to check in my forked repo.
Do you think it's a better solution comparing with current one? Note that I don't know whether we have the compatible concerns, so please let me know if the underlying layout calculation is crucial.
@elfenpiff @elBoberido @orecham
Contributor guide
Research direction
Start in iceoryx2/src/service/static_config/message_type_details.rs at the sample_layout implementation and compare its current unsafe calculation with the proposed Rust Layout approach in the linked fork commit. Check whether the resulting layout must remain compatible with the C++ implementation and existing shared-memory expectations; done means an agreed approach with the resulting layout validated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- distributed-systems
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100