What is the maximum number of methods for a .NET class

The name asks for everything, in fact, but still, for completeness:

Hi, I am writing a small compilation tool on the .NET platform, and trying to optimize it, I came across a question that I can - it is not easy to find an answer from ECMA standards for the Common Language Infrastructure ( CLI ).

What is the maximum number of methods a single class can have? Is there a limit?

Edit

Thanks to Kelsey for pointing out the real test. Although I will still take care of what the actual limit is, for my real real purposes, I would like to know if it was 2 ^ 16/2 ^ 32-or-2 ^ 31-1, as he noted, he Apparently, clearly above 64K methods in the class.

+7
source share
3 answers

An interesting question, but I don’t know why you ever get in the limit in reality, so the answer may not be so useful, because it is a large number.

I found this thread where someone wrote the following test, to actually create a class with an increase in the number of functions, to see where the breakpoint was:

namespace MethodCountLimitFinder { class Program { [System.STAThreadAttribute] static void Main ( string [] args ) { Microsoft.CSharp.CSharpCodeProvider provider = new Microsoft.CSharp.CSharpCodeProvider() ; System.CodeDom.Compiler.CompilerParameters cp = new System.CodeDom.Compiler.CompilerParameters() ; cp.GenerateExecutable = false ; cp.GenerateInMemory = true ; System.CodeDom.Compiler.CompilerResults cr = null ; System.Text.StringBuilder inner = new System.Text.StringBuilder ( "namespace Tester { class Test {" ) ; int methodCount = 1000000 ; while ( true ) { System.Console.WriteLine ( methodCount ) ; for ( int i = methodCount ; i > 0 ; i-- ) { inner.AppendFormat ( "void M{0}(){{}}\n" , methodCount++ ) ; } inner.Append ( "}}" ) ; cr = provider.CompileAssemblyFromSource ( cp , inner.ToString() ) ; if ( cr.Errors.Count > 0 ) { break; } inner.Remove ( inner.Length - 2 , 2 ) ; } foreach ( System.CodeDom.Compiler.CompilerError ce in cr.Errors ) { System.Console.WriteLine ( ce.ToString() ) ; } } } } 

According to the results, it looks like a resource-dependent, not a specifier, which is most likely not defined unless you bind it to a 32/64-bit index link or something that I do not consider realistic, since you will end up in resource constraints, probably anyway.

Test exceeded 200k + before crash due to lack of resources.

Again, interesting but not all that is useful for IMO information.

+5
source

Found several links that may help you.

The limit for Java is 65535

A similar question in SO for .NET

Related posts

Object of god

+2
source

I think you will need to look at the unmanaged interfaces in the CLR to determine the metadata structures in order to find the size limits for these structures. This answer (and comments) already notes that these are ~ 16 million (24-bit index) methods per assembly (not type).

As an alternative, consider reflection methods that return arrays, and there is a 1 GB limit per object in the current .NET runtime, so the maximum is 1024^3/sizeof(MethodIndo) .

+2
source

All Articles