From dc4ac88116e5216e80af6152bdce33aa6abdb332 Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Wed, 15 Nov 2023 01:01:09 +0200 Subject: [PATCH] Added copy for bytes --- src/BUTR.NativeAOT.Shared/Utils.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/BUTR.NativeAOT.Shared/Utils.cs b/src/BUTR.NativeAOT.Shared/Utils.cs index 3ec6cf0..f3d121b 100644 --- a/src/BUTR.NativeAOT.Shared/Utils.cs +++ b/src/BUTR.NativeAOT.Shared/Utils.cs @@ -67,6 +67,13 @@ public static string SerializeJson(TValue? value, JsonTypeInfo j } + private static unsafe SafeDataMallocHandle Copy(in ReadOnlySpan data, bool isOwner) + { + var dst = (byte*) Allocator.Alloc(new UIntPtr((uint) data.Length)); + data.CopyTo(new Span(dst, data.Length)); + return new(dst, data.Length, isOwner); + } + public static unsafe SafeStringMallocHandle Copy(in ReadOnlySpan str, bool isOwner) { var size = (uint) ((str.Length + 1) * 2);