Is static extern void Buffer.InternalBlockCopy part of .NET Framework?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Is static extern void Buffer.InternalBlockCopy part of .NET Framework?



I study how FileStream is implemented in C# and in the Read(..) method I can see:


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



Where Buffer.InternalBlockCopy points to definition (bellow) in buffer.cs. The method BlockCopy is defined as static extern. Where is this method defined? It is part of .NET? It is managed or 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);
..





Possibly related: What's the point of MethodImplOptions.InternalCall?
– Nisarg Shah
Aug 10 at 6:54






If you look around the coreclr repo you can usually find these methods (of course this is the core clr implementation not the full .net framework). This one is here. Look for Buffer::BlockCopy.
– mike z
Aug 10 at 7:01





@mikez Thanks, that is what I was looking for. Now I see that in Core it is few checks and memmove.
– qub1n
Aug 10 at 7:24




1 Answer
1



Well, the extern keyword means that the method is defined outside C# code, and the


extern


[MethodImplAttribute(MethodImplOptions.InternalCall)]



means that it calls a method defined inside Common Language Runtime.



After MethodImplOptions docs:


MethodImplOptions



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






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard