C# function normal return value VS out or ref argument -


I have a method in C # that returns a very large array (or some other large data structure for that matter) need to ).

Is there any benefit in using ref or out parameters instead of standard return value?

On

  There is any performance or other advantage in using the void function (sometype input, referee operaire) 

  The amount of stack space used on 32-bit  

  • enum: 4 bytes
  • Li: Four bytes
  • Bit: 4 bytes
  • Int: 4 bytes
  • Long: 8 bytes
  • Float: 4 bytes
  • Repeat: 8 Bytes
  • Decimal: 16 Bytes
  • Structure: Runtime size of architecture
    • Array: 4 bytes
    • Object: 4 bytes
    • Interface: 4 bytes
    • Pointer: 4 bytes
    • Class examples: 4 bytes

    There are reference types below the line, their size is 64 -bit will be doubled on the processor.

    For a steady method call, the first 2 logic which is up to 4b will be via the Yttes CPU registers, not the stack. Only an argument will be passed through the registers for an example method call. The remaining stacks are passed on. Supports to pass 4 arguments through a 64-bit processor registers.

    It is clear from the list, only once you have to consider refusing an argument from the referee, for this, the general guidance for structures is to do this when the structure exceeds 16 bytes. It is not always easy to estimate the size of the structure, usually up to 4 fields. Less if those areas are double, long or decimal, usually in this direction, it is advisable to change your structure in class, for this reason only.

    Also keep in mind that is happy with a 32-bit processor as a byte or deliberately at least one argument is currently available 64- Bit processor.


    A method return value, the actual subject of your question is almost always returned to a CPU register. Most of the types are comfortable in EX or ADX: EX registers, an FTP for floating point value register. The only exceptions are large structures and decimals, they are too big to fit into a register, they are called by returning the reserve position on the stack for the return value and passing the 4-byte pointer to the place as the argument of the method.


    Comments