viirya commented on code in PR #2883: URL: https://github.com/apache/arrow-rs/pull/2883#discussion_r996473145
########## arrow/src/ipc/reader.rs: ########## @@ -499,6 +512,24 @@ fn create_primitive_array( make_array(array_data) } +/// Checks if given `Buffer` is properly aligned with `T`. +/// If not, copying the data and padded it for alignment. +fn get_aligned_buffer<T>(buffer: &Buffer, length: usize) -> Buffer { + let ptr = buffer.as_ptr(); + let align_req = std::mem::align_of::<T>(); + let align_offset = ptr.align_offset(align_req); + // The buffer is not aligned properly. The writer might use a smaller alignment + // e.g. 8 bytes, but on some platform (e.g. ARM) i128 requires 16 bytes alignment. + // We need to copy the buffer as fallback. + if align_offset != 0 { + let len_in_bytes = (length * std::mem::size_of::<T>()).min(buffer.len()); Review Comment: Hm? Why? `buffer.len()` is the actual length in bytes, no? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org