From 5863a9f31f1844b33a5aeb1c9108c8517600ab05 Mon Sep 17 00:00:00 2001 From: Paddy Horan Date: Wed, 6 Feb 2019 11:48:58 +0100 Subject: [PATCH] ARROW-4488: [Rust] From AsRef<[u8]> for Buffer does not ensure correct padding Padding for all memory allocations needs to be a multiple of 64 bytes to make SIMD implementations easier and more efficient to implement. Author: Paddy Horan Closes #3568 from paddyhoran/asref-padding and squashes the following commits: 05cb0e99 Ensures padding to a multiple of 64 bytes --- rust/arrow/src/buffer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rust/arrow/src/buffer.rs b/rust/arrow/src/buffer.rs index 6172445ec821e..70aea63aedcb2 100644 --- a/rust/arrow/src/buffer.rs +++ b/rust/arrow/src/buffer.rs @@ -132,7 +132,8 @@ impl> From for Buffer { // allocate aligned memory buffer let slice = p.as_ref(); let len = slice.len() * mem::size_of::(); - let buffer = memory::allocate_aligned(len).unwrap(); + let capacity = bit_util::round_upto_multiple_of_64(len); + let buffer = memory::allocate_aligned(capacity).unwrap(); unsafe { memory::memcpy(buffer, slice.as_ptr(), len); }