Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-4956: [C#] Allow ArrowBuffers to wrap external Memory #3971

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion csharp/src/Apache.Arrow/ArrowBuffer.cs
Expand Up @@ -23,7 +23,7 @@ namespace Apache.Arrow
{
public static ArrowBuffer Empty => new ArrowBuffer(Memory<byte>.Empty);

internal ArrowBuffer(ReadOnlyMemory<byte> data)
public ArrowBuffer(ReadOnlyMemory<byte> data)
{
Memory = data;
}
Expand Down
18 changes: 18 additions & 0 deletions csharp/test/Apache.Arrow.Tests/ArrowBufferTests.cs
Expand Up @@ -15,6 +15,7 @@

using Apache.Arrow.Tests.Fixtures;
using System;
using System.Runtime.InteropServices;
using Xunit;

namespace Apache.Arrow.Tests
Expand Down Expand Up @@ -81,5 +82,22 @@ public void HasZeroPadding()
}

}

[Fact]
public void TestExternalMemoryWrappedAsArrowBuffer()
{
Memory<byte> memory = new byte[sizeof(int) * 3];
Span<byte> spanOfBytes = memory.Span;
var span = spanOfBytes.CastTo<int>();
span[0] = 0;
span[1] = 1;
span[2] = 2;

ArrowBuffer buffer = new ArrowBuffer(memory);
Assert.Equal(2, buffer.Span.CastTo<int>()[2]);

span[2] = 10;
Assert.Equal(10, buffer.Span.CastTo<int>()[2]);
}
}
}