Skip to content

Reflection method

George George

Asked Sep 7, 2008, 7:06 PM EDT5 answers
Share
LinkedInX

Hello everyone,


Sometimes I saw code which does not store reflection data structure MethodInfo, but stores MethodHandle each time and converts MethodHandle to MethodInfo (using GetMethodFromHandle) when MethodInfo is used to invoke the specific method using reflection.

My understanding is,

1. Using method handle could save memory;
2. But each time doing conversion from method handle to method info uses additional time.

So, it is a memory footprint/performance trade-off of choosing method info and method handle.

My questions is whether my above understanding of whether to use method handle or method info is correct. If not, what are the correct points?


thanks in advance,
George

4 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    +1
    Ok george, you say
    1. Using method handle could save memory;
    2. But each time doing conversion from method handle to method info uses additional time.
    but thinks couldn't be seen from this corner as method handle and method info are not designed for the same purpose whereas it seems to be.
    the method handle is used in case where the purpuse is purely the execution of the method. In the other hand if you want to
    store any other information about the method then you make use of the MethodInfo, this could be remarked from the set of properties and members of each class

    +1
  • +1

    Do you mean there is no need to store method info and only method handle is needed (please feel free to correct me if I wrongly understand your points)? If yes, I do not agree, since in order to invoke a method, method info object is needed other than the method handle.

    Any comments?

     

    regards,

    George

    +1
  • Bechir Bejaoui
    +1
    Not exactly, you have to preform a conversion  to a MethodInfo object in order to do invoke , of corse. I guess I calrify the issue.
    +1
  • +1

    Thanks, it is clear now.

     

    regards,

    George

    +1
  • 1 short reply
    • Bechir Bejaoui
      +1
      Not at all, George
      +1