代码之家  ›  专栏  ›  技术社区  ›  Tomas Kubes

静态extern void Buffer.InternalBlockCopy是.NET框架的一部分吗?

  •  2
  • Tomas Kubes  · 技术社区  · 7 年前

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

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

    buffer.cs . 方法BlockCopy被定义为static extern。这个方法是在哪里定义的?它是.NET的一部分?它是托管的还是本地的?

    [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);
    ..
    }
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   V0ldek    7 年前

    嗯,那个 extern keyword 意味着定义了方法 ,以及

    [MethodImplAttribute(MethodImplOptions.InternalCall)]
    

    意味着它调用公共语言运行库中定义的方法。

    MethodImplOptions docs :

    推荐文章