Java inline functions

Source: Internet
Author: User

Before you say inline functions, let's talk about the procedure for calling a function.

Calling a function actually transfers the program execution order to an address in memory that is stored in the function, executes the program contents of the function, and then returns to the
Go to the place before executing the function. This transfer operation requires that the site be protected and the address of the memory to be executed before it is transferred back to the scene, and the original
The storage address continues to execute. This is usually called the stack and the stack. Therefore, function calls have a certain amount of time and space overhead. So for those function bodies
Code is not very large, and frequently called functions, this time and space consumption will be very large.

How to solve this problem of performance consumption, this time need to introduce an inline function. The inline function is when the program compiles, the compiler will appear in the program
The call expression for an inline function is replaced directly with the function body of the inline function. Obviously, this will not cause a reversal of the problem, but because the compiler
When the code in the function body is replaced in the program, it increases the target program code, which increases the space overhead, but not when the function is called on the time consignment.
So large, it can be seen that it is at the expense of increasing the target code in exchange for time savings.

When we learn to write C code in college, we learn to define short logic in a macro. The advantage of this is that when the compiler compiles, it will be used
To the macro, replace it directly with the macro's code. This eliminates the need to press the stack, the stack, and the arguments like the calling method. Improved performance. of the inline function
is treated like a macro, but differs from a macro in that the inline function has its own characteristics (type, scope, and so on)

Java inline functions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.