Function Inlining in C++ | Modern Cpp Series Ep. 109

  Рет қаралды 4,163

Mike Shah

Mike Shah

Күн бұрын

Пікірлер: 42
@henrijohansson2482
@henrijohansson2482 9 ай бұрын
I love the pros and cons. Now I know that if I might want to reduce executer size I might turn inline functions back to regular ones.
@MikeShah
@MikeShah 9 ай бұрын
Cheers! Generally inlining is good for performance with the right functions, but always with tradeoffs 🙂
@mytech6779
@mytech6779 25 күн бұрын
I can see inline being a performance loss in some corner cases due to the effect on the L1i cache if a function is called several times in close proximity and after branching (in both branches) a function could stay in cache while many inlined copies would be constantly loaded and evicted. This would certainly be very dependent on the specific code with specific hardware and need testing due to all of the unknowns.
@MikeShah
@MikeShah 25 күн бұрын
Indeed, inlining can make code size large and potentially blowup the instruction cache. That said, inlining may enable other optimizations -- very much depends on code, but usually a win.
@mytech6779
@mytech6779 24 күн бұрын
@@MikeShah On some further research "cache thrashing" seems to be the term that describes what I was trying to get at. And thrashing can also be an issue on the data side with certain access patterns.
@MikeShah
@MikeShah 24 күн бұрын
@mytech6779 yup absolutely!
@sachinjain6429
@sachinjain6429 Жыл бұрын
sir , i think you are underrated , and the quality of your content his highly professional and to the point , thank you for such nice explanations
@MikeShah
@MikeShah Жыл бұрын
Cheers, thank you for the kind words! Feel free to spread the word :)
@CPP_malloc
@CPP_malloc Жыл бұрын
inline in C++ works differently to C language inline specifier in C means to the compiler "inline this function when it is possible to do that". but in inline in C++ language means to the compiler "don't complain about two declarations of a function "or variable in C++17" in two different translation units, and only choose one address of one function to be exposed in the external in linkage table". and the meaning of "C inline" in C++ is only left to the optimization of the compiler, if you used -O3 optimization level you will get it inlined. Or by using some attributes to force the compiler to inline it, but it isn't C++ standard it is only a feature in gcc, as __forceinline is an attribute in MSVC for the same purpose.
@MikeShah
@MikeShah Жыл бұрын
I'm going to cover inline variables (I believe introduced in c++17) shortly which covers some of the linkage issues you discussed :)
@CPP_malloc
@CPP_malloc Жыл бұрын
@@MikeShah exactly, your videos are awesome and prepared to be simple to the viewer I like watching them in case there is something I don't know. Btw in your next video you can cover two topics "template variables in C++14" and "inline variables in C++17" Because it isn't much to put them both in the same video length. I wish you good luck and all the best Mike Shah.
@MikeShah
@MikeShah Жыл бұрын
@@CPP_malloc Cheers, thank you for the kind words! Will consider your suggestion!
@mdatab
@mdatab Жыл бұрын
I very much appreciate your videos about C++. Thank you very much for providing such helpful content. Perhaps you could occasionally make another video (or even a series) about your vim setup that includes tips on configuring vim for C++?
@MikeShah
@MikeShah Жыл бұрын
Cheeres, thank you Martin! I use a relatively vanilla VIM, but I'll add that to the video wishlist :)
@MartinCordova
@MartinCordova Жыл бұрын
A clear explanation, and again, having the chance to view the things happening in assembly language is a big plus, great content all of yours. I now use constexpr for all my functions with GCC-13 and -std=c++23, even for lambdas, it does the inlining plus the compile-time (if possible). Mike, are you available (I mean consulting services) for code reviews? I would like to have a quotation for a specific case in one of my open-source projects
@MikeShah
@MikeShah Жыл бұрын
Cheers! Feel free to send me an e-mail regarding opportunities -- on occassion I have time for consulting work.
@mister-ace
@mister-ace 10 ай бұрын
Hi, what resources I can read to understand that assembly code on the right? Thank you.
@MikeShah
@MikeShah 10 ай бұрын
I have a few assembly videos, otherwise some combination of courses, and writing very small programs can help understand assembly (e.g. start with an assignment statement, a loop, etc.)
@saifsuleiman1171
@saifsuleiman1171 Жыл бұрын
Hi Mike, thanks for this great c++ series, looking forward for more content. In the mean time I will start watching your other series, currently I am interested in "C++ Software Design and Design Patterns", "Modern C++ (cpp) Concurrency", "Introduction to OpenGL", "SDL2 Simple Directmedia Layer" and "SFML - Simple Fast Media Library"
@MikeShah
@MikeShah Жыл бұрын
Cheers, thank you for the kind words! More C++ coming, a few more design patterns videos first :)
@monty6393
@monty6393 Жыл бұрын
Wooohooo... Compiler Explorer always makes me feel good .. I already knew about inline function `hint` to the compiler but what was the key takeaway for me was the attribute always inline that was something new... Thanks for the video... What's your plan for this year in this channel? Have you given a thought on Doing something in Rust?
@MikeShah
@MikeShah Жыл бұрын
Cheers! Yes, very cool! As for the channel, I have a backlog of at least 100 videos to film. :) At some point I need to learn some more Rust, perhaps a longer form introduction would be something I put together. That said, tons of DLang, C, C++, SDL2, and OpenGL videos queued up and ready to be produced :)
@monty6393
@monty6393 Жыл бұрын
@@MikeShah okay Professor .. Btw these days I am thinking of doing some good project in c/ c++ would you suggest me something ?
@MikeShah
@MikeShah Жыл бұрын
@@monty6393 I like doing small games (breakout, tetris, etc.) or text editors. I think Austin Henley has a good blog on projects, and at some point I'll do a video on this topic :)
@monty6393
@monty6393 Жыл бұрын
@@MikeShah Thanks for the suggestion professor
@dogdog5994
@dogdog5994 Жыл бұрын
I suggest a video in the C language series about C11 threads, the POSIX pthread library and c11 threads vs POSIX pthread.
@MikeShah
@MikeShah Жыл бұрын
Good idea :) At the least I will cover pthreads and locks a bit in the C series
@CorpoWolf
@CorpoWolf 7 ай бұрын
Isn't this what the pre-compiler and macro's are for? I feel pain for knowing what inline is now.
@MikeShah
@MikeShah 7 ай бұрын
Similar idea to a macro -- macros are merely textual replacements. The 'inline' keywords still performs various type checking prior to code optimization. Also, it's not necessarily guaranteed an inline function will be inline -- it's just a request.
@VoidloniXaarii
@VoidloniXaarii Жыл бұрын
So love all your cpp vidz
@MikeShah
@MikeShah 10 ай бұрын
Cheers!
@VoidloniXaarii
@VoidloniXaarii 10 ай бұрын
@@MikeShah干杯
@_w62_
@_w62_ Жыл бұрын
Would you consdier making a series on something say, "the internal workings of C++ with the compiler explorer/objdump"? Explaining to us the internal workings of the C++ langauge? If basic asm is needed, I can learn that.
@MikeShah
@MikeShah Жыл бұрын
Thanks for the suggestion -- I may give a talk on compiling/linking in the future on this. Will keep this as a note for the future.
@mirzakadic9174
@mirzakadic9174 Жыл бұрын
This video earned you a subscriber :)
@MikeShah
@MikeShah Жыл бұрын
Cheers! Welcome!
@abhishek_karki
@abhishek_karki Жыл бұрын
Do you also have Linux system programming using C++ in your pipeline for this year?
@Southpaw101
@Southpaw101 Жыл бұрын
That will be tremendously useful if MikeS can accommodate that.
@MikeShah
@MikeShah Жыл бұрын
@@Southpaw101 Will note this as a suggestion in the C++ playlist.
@monty6393
@monty6393 Жыл бұрын
Cool cool . More closer to the hardware
@windowsbuilderthegreat3121
@windowsbuilderthegreat3121 Жыл бұрын
Which version of C++was this feature introduced
@MikeShah
@MikeShah Жыл бұрын
I believe at least C++98 or C99
УДИВИЛ ВСЕХ СВОИМ УХОДОМ!😳 #shorts
00:49
Чистка воды совком от денег
00:32
FD Vasya
Рет қаралды 4,8 МЛН
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 43 МЛН
why do header files even exist?
10:53
Low Level
Рет қаралды 434 М.
Advanced Topics: Function Inlining
6:49
Nick
Рет қаралды 7 М.
inline в C++
15:05
Volodya Mozhenkov
Рет қаралды 2,6 М.
SOME UNIQUE C++ CODE! // Pacman Clone Code Review
26:42
The Cherno
Рет қаралды 288 М.
The Inline Keyword in C.
16:18
Jacob Sorber
Рет қаралды 58 М.
Introduction to constexpr | Modern Cpp Series Ep. 86
10:56
Mike Shah
Рет қаралды 12 М.
C++ libraries and what inline has to do with them
29:02
Code for yourself
Рет қаралды 3,8 М.
УДИВИЛ ВСЕХ СВОИМ УХОДОМ!😳 #shorts
00:49