Is it possible to make a built-in function in vb.net?

the question is in the title

+5
source share
7 answers

An attachment is a CLR (JIT), and there are some conditions when a function is built-in:

  • The code size is less than 32 bytes of IL.
  • The function does not contain "complex" constructs, for example. hinges, switch, etc.
  • The function does not contain try / catch / finally.
  • The function is not declared virtual.

As you will probably find out, 32 bytes is not very good from the point of view of code; it is suitable for quick and small testing of if-else conditions, getters / seters properties. I don’t think you can get any speed from embedding more code.

+7
source

, , , JIT- - . "inline", , , - - #, , :

public IEnumerable<int> Foo()
{
    int[] numbers = new[] { 1, 5, 2, 5, 6 };

    return numbers.Select(x => x+10);
}

x => x+10 ( ) " " , ​​ "" .

, VB9 :

Dim len As Func(Of String, Integer) = Function(x) x.Length       
Console.WriteLine(len("foo"))

, VB9 #, , , , Action<T> ( ) VB9, # . , VB9, # .

VB10 - VB.

, , , :)

+13

5 (???)

.net 4.5

<MethodImplAttribute(MethodImplOptions.AggressiveInlining)>
+4

.NET , , , . , , ++ inline , .

+2

, :

, . , , . , CPU System.Reflection.MethodBase.GetCurrentMethod.Name, , , , , , :

Public Inline Function GetMyname(iLogLevel) as string
  if iLogLevel < 3 then return ""
  return System.Reflection.MethodBase.GetCurrentMethod.Name()
End Function 

, :

(2, GetMyname (2) ": - " )

GetMyname() ( ), , , "GetMyName" - .

, ( CLR!), " .Net". ?

+2

inline, JIT , .

+1

Noting Tom's problem on May 11, I have to say that if you have an application that is really performance critical, then using a language that depends on the CLR is probably not the best option.

In fact, object-oriented design is probably not your best bet. You can seriously take a look at C as an alternative.

0
source

All Articles