I want to know how to find the amount of memory that a function uses while it is used as an inline function and an ordinary function to make the function usage efficient.
I want to calculate the exact memory usage in both cases.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to clarify whether you’re concerned about program size or runtime memory usage (stack versus registers).
Further, for any function that inherently has a fair bit of work to do for each call site, there’s insignificant benefit from inlining in terms of program size. For any function that inherently needs to use a significant amount of memory – for a ballpark feel figure say more than a hundred bytes – inlining or not won’t make any difference. But “inherently” encodes the fact that each call site may have different actual needs, so inlining may help if compile-time determination of needs of specific call sites allows significant optimisation opportunities (for example – dead code elimination).
Inline functions are effectively substituted at each point they’re called, then optimised – that optimisation may change the registers and memory they use – whether you mean memory used for machine code instruction (i.e. the program), or memory used for stack versus registers. Optimisations such as dead code elimination – along with the memory usage implied by that code – may be possible for one caller but not another, but if that code branch wasn’t executed when calling an out-of-line function there’s unlikely to be much difference in the memory usage anyway. Countering this, depending on the size of the function, how much optimisation can typically happen after inlining, how many call sites there are, and how much code is needed to prepare and pass arguments when calling out-of-line, either approach may yield more or less overall code bloat. With inling there’s more risk of excessive code bloat, but then the compiler will typically choose not to honour an “inline” keyword hint when reasonable thresholds are exceeded.
As with most optimisation options, if you care you should measure for your specific application with realistic data/event loads.