Skip to content

Commit

Permalink
Added copy for bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Nov 14, 2023
1 parent 116b093 commit dc4ac88
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/BUTR.NativeAOT.Shared/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public static string SerializeJson<TValue>(TValue? value, JsonTypeInfo<TValue> j
}


private static unsafe SafeDataMallocHandle Copy(in ReadOnlySpan<byte> data, bool isOwner)
{
var dst = (byte*) Allocator.Alloc(new UIntPtr((uint) data.Length));
data.CopyTo(new Span<byte>(dst, data.Length));
return new(dst, data.Length, isOwner);
}

public static unsafe SafeStringMallocHandle Copy(in ReadOnlySpan<char> str, bool isOwner)
{
var size = (uint) ((str.Length + 1) * 2);
Expand Down

0 comments on commit dc4ac88

Please sign in to comment.