From f375e1c0bbf5e31742a5f8fbc763cdf4f4fb42db Mon Sep 17 00:00:00 2001 From: Eli Belash Date: Wed, 21 Aug 2019 23:33:54 +0300 Subject: [PATCH] Tensor.BufferToArray(): Fixed to use long instead of int. --- src/TensorFlowNET.Core/Tensors/Tensor.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/TensorFlowNET.Core/Tensors/Tensor.cs b/src/TensorFlowNET.Core/Tensors/Tensor.cs index bccc2569..6f4cc21a 100644 --- a/src/TensorFlowNET.Core/Tensors/Tensor.cs +++ b/src/TensorFlowNET.Core/Tensors/Tensor.cs @@ -372,9 +372,16 @@ namespace Tensorflow /// public byte[] BufferToArray() { - var data = new byte[bytesize]; - Marshal.Copy(buffer, data, 0, (int) bytesize); - return data; + unsafe + { + // ReSharper disable once LocalVariableHidesMember + var bytesize = (long) this.bytesize; + var data = new byte[bytesize]; + fixed (byte* dst = data) + System.Buffer.MemoryCopy(buffer.ToPointer(), dst, bytesize, bytesize); + + return data; + } } /// Used internally in ToArray<T>