SHA256
forked from ADOFAIEditorForum/ADOFAIRenderer
Reduce Memory Copy When Frame Capture Success
This commit is contained in:
1 parent
036216c006
commit
6bd4a8975e
3 files changed
+32
-11
No files matched your search
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace ADOFAIRenderer.Util
|
||||
{
|
||||
public static class StreamUtil
|
||||
{
|
||||
public static void WriteNativePtrToStream(IntPtr nativePtr, int length, Stream destinationStream)
|
||||
{
|
||||
if (nativePtr == IntPtr.Zero)
|
||||
throw new ArgumentNullException(nameof(nativePtr));
|
||||
if (length <= 0) return;
|
||||
|
||||
unsafe
|
||||
{
|
||||
// Create an unmanaged memory stream that wraps the native pointer
|
||||
// (This does not allocate new memory; it references the existing pointer)
|
||||
using var unmanagedStream = new UnmanagedMemoryStream((byte*)nativePtr, length);
|
||||
// Copy the data directly into your target stream
|
||||
unmanagedStream.CopyTo(destinationStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user