The amount of stack space used on an x86 32-bit processor to pass arguments of various types:
- byte: 4 bytes
- bool: 4 bytes
- enumeration: 4 bytes
- char: 4 bytes
- short: 4 bytes
- int: 4 bytes
- long: 8 bytes
- float: 4 bytes
- double: 8 bytes
- decimal: 16 bytes
- struct: structure runtime
- string: 4 bytes
- array: 4 bytes
- object: 4 bytes
- interface: 4 bytes
- pointer: 4 bytes
- class instance: 4 bytes
Those below the line are reference types; their size is doubled on a 64-bit processor.
To call the static method, the first 2 arguments, which contain up to 4 bytes, will be passed through the CPU registers, and not onto the stack. To invoke an instance method, only one argument will be passed through registers. The rest are passed on the stack. The 64-bit processor supports passing 4 arguments through registers.
As you can see from the list, the only time you should consider passing a ref argument is for structures. The normal guide for this is to do this when the structure is larger than 16 bytes. It is not always easy to guess the size of the execution time of the structure, usually up to 4 fields. Less if these fields are double, long or decimal. This rule usually recommends turning your structure into a class for this reason.
Also note that there is no saving that passes an argument as byte or short intentionally, int is the type that a 32-bit processor satisfies. The same goes for the currently available 64-bit processors.
The return value of the method, the real topic of your question is almost always returned in the CPU register. Most types are conveniently embedded in the eax or edx registers: eax, the FPU register for floating point values. The only exceptions are large structures and decimal numbers; they are too large to be case-sensitive. They are called by reserving the stack space for the return value and passing a 4-byte pointer to this space as an argument to the method.
Hans passant
source share