静态库性能 - 可以内联调用吗? [英] Static Library Performance - Possible to inline calls?

查看:31
本文介绍了静态库性能 - 可以内联调用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试制作游戏引擎,我从制作数学基础开始(矢量、矩阵和点类.)我想制作一个静态库文件 (.lib),然后我可以在游戏引擎的其余部分需要它时使用它.

I've been trying to make an attempt to make a Game Engine, and I started out by making the Mathmatical foundation ( Vector, Matrix and Point classes. ) I would like to make a static library file (.lib) which I can then use in the rest of my Game Engine where it's needed.

我想知道的是以下内容.由于库中的大多数函数都需要尽可能快.我想查看函数,例如内联 Vector 类.编译器能自动做到这一点吗?还是需要某种提示?

What I was wondering is the following. Since most functions in the library need to be as fast as possible. I'd like to see the functions for example a Vector class being inlined. Can the compiler automatically do this? Or is some kind of hint needed?

我知道我可以将所有源代码放在头文件中,但我认为这不是一个真正优雅的解决方案,因为某些函数可能太大而无法内联.(头文件对于使用它们的人来说不会有点混乱.)

I know I can put all the source in the header files but I think that's not really an elegant solution since some functions might be too large to be inlined. ( Header files wouldn't kind of be messy for the poeple using them. )

希望大家帮帮我.

基督徒

推荐答案

只有在编译单元具有源代码可见性的情况下,才能保证函数的内联与当前的编译器技术一起使用.一旦将代码编译到库中,无论函数做什么,它都不会内联该函数.

Inlining of functions is only guaranteed to work with current compiler technology if the compileunit has visibility of the source code. Once you compile code into a library, it will not inline the function, no matter what the function does.

有一些整个程序优化"方案(至少在 MSVC 和 GCC 中可用,也可能在其他编译器中可用)产生的目标文件"只是机器代码的一部分,因此一些有关源代码想要什么"的信息可用于最终代码生成/链接阶段以移动代码、执行内联等,但这仅适用于所有源文件在编译时可用的情况.一旦某些东西被制作成最终的目标代码(您的静态库就是它),它就不会成为内联"部分.

There is some "whole program optimization" schemes (available in at least MSVC and GCC, probably other compilers too) that produce a "object file" that is only part of the way to machine-code, so that some of the information about "what the source code wanted" is available to the final code-generation/linking stage to move code around, perform inlining and such, but this is only applicable when all source-files are available at the compile-time. Once something is made into final object code (which your static library is), it won't be making it into the "inliner" part.

显然,如果您有类,它们将在头文件中,因此如果您将适合内联的函数放入头文件中,编译器会做正确的事情.

Obviously, if you have classes, they will be in header files, so if you put functions suitable for inlining into the header file, the compiler will do the right thing.

这篇关于静态库性能 - 可以内联调用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆