Skip to content

Commit

Permalink
[#56] Adjust roadmap and use maybeuninit write instead of unsafe copy
Browse files Browse the repository at this point in the history
  • Loading branch information
elfenpiff committed Dec 27, 2023
1 parent dc84df5 commit f7a9966
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
2 changes: 2 additions & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* [ ] Introduce elementary types, look into: `simple-si-units` crate
* Add types like: memory size, percentage, strict percentage (0..100), data throughput, resolution
(further types found in informatics)
* [ ] Add `derive` proc macro to ensure that only shm compatible types can be
transferred via zero-copy

## Language Bindings

Expand Down
21 changes: 6 additions & 15 deletions iceoryx2-bb/container/src/byte_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,13 @@ impl<const CAPACITY: usize> FixedSizeByteString<CAPACITY> {
pub fn from_bytes_truncated(bytes: &[u8]) -> Self {
let mut new_self = Self::new();
new_self.len = std::cmp::min(bytes.len(), CAPACITY);
unsafe {
std::ptr::copy(
bytes.as_ptr(),
new_self.data.as_ptr() as *mut u8,
bytes.len(),
)
};
for (i, byte) in bytes.iter().enumerate().take(new_self.len) {
new_self.data[i].write(*byte);
}

let zero = 0u8;
unsafe {
std::ptr::copy(
&zero,
new_self.data.as_ptr().add(new_self.len) as *mut u8,
1,
)
};
if new_self.len < CAPACITY {
new_self.data[new_self.len].write(0);
}

new_self
}
Expand Down

0 comments on commit f7a9966

Please sign in to comment.