Getting The Size of a C++ Function

后端 未结 16 2170
醉酒成梦
醉酒成梦 2020-12-06 09:37

I was reading this question because I\'m trying to find the size of a function in a C++ program, It is hinted at that there may be a way that is platform specific. My target

16条回答
  •  忘掉有多难
    2020-12-06 10:08

    What do you mean "size of a function"?

    If you mean a function pointer than it is always just 4 bytes for 32bits systems.

    If you mean the size of the code than you should just disassemble generated code and find the entry point and closest ret call. One way to do it is to read the instruction pointer register at the beginning and at the end of your function.

    If you want to figure out the number of instructions called in the average case for your function you can use profilers and divide the number of retired instructions on the number of calls.

提交回复
热议问题