Skip to content

IArrayBuffer.WriteBytes taking a span/memory? #632

Description

@oconnor0

I have a situation where I have some data sitting in a class that exposes access to a ReadOnlyMemory<bytes>. I'd like to be able to move the bytes directly from this into V8 via IArrayBuffer.WriteBytes, but I have to convert the ReadOnlyMemory to a byte[] and then copy that in. Would it be feasible to add a method like the following to IArrayBuffer?

ulong WriteBytes(
	ReadOnlySpan<byte> source,
	ulong offset
)

I believe the conversion from ReadOnlyMemory to ReadOnlySpan is fast and should avoid one copy of the byte array.

I guess this is somewhat dependent on WriteBytes immediately writing the bytes from C# to V8 vs keeping a reference to the source around.

This is not a high priority for me, just something I noticed today.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions