Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline function #8

Closed
jimin-kiim opened this issue Oct 20, 2022 · 0 comments
Closed

Inline function #8

jimin-kiim opened this issue Oct 20, 2022 · 0 comments

Comments

@jimin-kiim
Copy link
Owner

jimin-kiim commented Oct 20, 2022

  • general function
    • when the function is called, it moves to the codes where the function body is and come back to the original position.

Inline member function

  • compiler inserts the function body codes into the place of each function call
  • advantage :
    • can make the program faster
    • since it eliminates the process of jumping and coming back ( avoids overhead for function call)

      overhead : additional cost (time)

  • disadvantage :
    • the size of the program can be unnecessarily bigger
  • In most case, the rate of how much the speed is increased is little and it can make the program size unnecessarily bigger so inline function is not used. But there exist some cases that it's significant, not negligible and useful
  • the cases when the inline function is used
    • when the function is very short like 1 or 2 lines long.
    • when the function is called within a loop with a lot of iterations
  • how to declare the inline function
    • put the keyword 'inline' in front of the signature of the function declaration
    • when the definition of the member function is inside of the class, it's automatically become an inline function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant