I am referring to this discussion. I have never written any code in C or in C++ . I do not have any CS background. However I have been working as Java developer for 5 years and now I have decided to learn more about CS and do some catching up.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- Sorting 3 numbers without branching [closed]
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
Inlining refers to compile-time optimization where a small function of code will be injected into the calling function rather than require a separate call.
As already mentioned in other answers, inlining comes with a cost. Usually this is considered small, however when actually measuring you might be surprised and learn that it might be greater than what you gain (so what other people say is true: do not optimize unless you have measured).
It is worth noting that in the Linux kernel they started un-inlining originally inlined functions some time ago because the cost was too high (larger functions consumed more of the cpu memory cache, and the resulting cache misses were more expensive than just calling the function that were intended to be inlined). See "Chapter 15: The inline disease" in doc/Documentation/CodingStyle for more details.
Basically, in C/C++, the compiler can inline functions, which means that rather than making a function call to do that operation, the code will be added to the calling function's block, so it will be as though it had never been a separate function call.
This will go into more detail: http://www.codersource.net/cpp_tutorial_inline_functions.html
In that discussion, Jon Skeet mentions Client jvm (hotspot) v Server jvm with the performance improvements available at run-time if the JIT ( just-in-time ) compiler is allowed to bring time-based enhancements. That is "how it's done" in Java.
Originally, small sections of code that were not called from many places would be "inlined" by the compiler, meaning that what was called a singleton would be placed directly in the instruction pointer code path, doing a function branch and return costs more processor power than just unrolling to loop or function call and placing the instructions "right there"
Today, Singleton is the subject of multi-page discussions and loop-unrolling as well as something like inlining are somewhat removed from their original context(s). You can read Dov Bulka's very informed work on the matter to get the C/C++ take on the matter. For Java, study of it's rich lib's in java.util would better serve your needs than study of inlining and deep compiler issues - you can get hung on entrenched embattled intramural warfare on data structures, which gloss over calls into 16-bit code, and go no end on your learning curve.
You can do instanceof in Java, that resembles a vf-table ( no heat folks, please ) but think of it as you have been writing in a strongly typed language - and now will be writing in a language where string can runaway easily poking around where it has no business. I recently tried to write code that constructed an Image in Java, doing that from C code. I soon found myself looking at the oxr table for strong encryption - that has nothing to do with the code I was writing.
How would you write a string class in C/C++ that has a small buffer for strings under 32 bytes and traps pointers so that they only operate on the string?
Not trying to tease you or anything, it's just a really good place to start rather than inlining and compiler science.