gpt4 book ai didi

c# - static extern void Buffer.InternalBlockCopy 是 .NET Framework 的一部分吗?

转载 作者:行者123 更新时间:2023-11-30 16:40:11 24 4
gpt4 key购买 nike

我研究如何FileStream is implemented in C#在 Read(..) 方法中我可以看到:

n = ReadCore(_buffer, 0, _bufferSize);
...
Buffer.InternalBlockCopy(_buffer, _readPos, array, offset, n);
...

其中 Buffer.InternalBlockCopy 指向 buffer.cs 中的定义(如下) . BlockCopy 方法被定义为静态外部。这个方法在哪里定义的?它是.NET 的一部分?它是托管的还是 native 的?

[System.Runtime.InteropServices.ComVisible(true)]
public static class Buffer
{
// Copies from one primitive array to another primitive array without
// respecting types. This calls memmove internally. The count and
// offset parameters here are in bytes. If you want to use traditional
// array element indices and counts, use Array.Copy.
[System.Security.SecuritySafeCritical] // auto-generated
[ResourceExposure(ResourceScope.None)]
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void BlockCopy(Array src, int srcOffset,
Array dst, int dstOffset, int count);
..
}

最佳答案

嗯,extern keyword意味着该方法是在 C# 代码之外定义的,而

[MethodImplAttribute(MethodImplOptions.InternalCall)]

表示它调用公共(public)语言运行时中定义的方法。

MethodImplOptions docs 之后:

The call is internal, that is, it calls a method that is implemented within the common language runtime.

关于c# - static extern void Buffer.InternalBlockCopy 是 .NET Framework 的一部分吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51780601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com