I know the GC can/will move stuff around on the heap. But if you get a pointer to a method, would you ever risk that method being moved?
Second. If you have a pointer to a method is there an unsafe/quick way to invoke it?
But if you get a pointer to a method, would you ever risk that method being moved?
How are you planning on getting the pointer to the method? C# doesn't have such an operation!
Suppose for the sake of argument that you did. The answer to your question is no, methods aren't moved by the GC. Methods aren't deleted, so why would they be moved? You move something in order to compact the hole left behind by a deletion.
But you don't get a pointer to a method in the first place in C#. You get a delegate.
There are ways to get a raw pointer with marshaling code, but what's the point? You can't invoke it.
If you have a pointer to a method is there an unsafe/quick way to invoke it?
But you don't have a pointer to a method in C#, so again, the question is nonsensical.
You invoke a delegate by, well, invoking a delegate.
Now, again, if you somehow managed to get a pointer to a method in C#, is there a way to invoke it that is faster and lighter weight than making a delegate and then invoking that?
No. There is no way in C# to cause the compiler to generate a calli
instruction, which is what you need.
The feature is possible; I once played around with a prototype of the features you want. When last I saw the priority list it was very, very low on that list so I would not expect it soon.