内联问题 [英] inline question

查看:56
本文介绍了内联问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



因为内联不是mandetory,它取决于编译器内联某些

函数(或使用像fior GCC这样的开关),我的问题是有没有

内联的范围是什么时候它没有被声明为内联函数?

即编译器可能选择不内联某些内联函数,但是它是免费的b $ b它是免费的选择一个非内联函数来内联它?

我有一些简单的一行获取函数,而我想要内联的索引操作符是
。但是由于一些问题(比如我有一些循环

依赖,因此使用前向声明,因此不可能

在头文件中实现了一些get函数)。 />

其次,如果我在cpp

文件中构建一个带有getter函数的库,而不是标题,(并且它没有内联),它是否意味着

内联的优化范围丢失了吗?如果它甚至是
有一个函数调用,它的成本是多少(与内联的

版本相比),因为它是一个吸气剂,因此没有任何

参数列表。

这些获取函数返回某种容器,依次使用
a类来返回一个开始&结束容器的迭代器。 (即一个

视图类在原始

容器的帮助下构造一对迭代器,该容器的引用包含在某个范围内,并返回)。

Hi,
As inline is not mandetory, it depends on compiler to inline certain
function (or using switch like fior GCC), my question is there any
scope for inlining when it is not declared as inline function?
i.e compiler may choose not to inline certain inline function, but is
it free to choose a non inline function to inline it?
I have some simple one line get function, and index operators which I
want to get inlined. But due to some problem (like I have some circular
dependency, thus use forward declaration, and hence not possible to
have some get function implemented in header).

Secondly, If i build a library with the getter function in the cpp
file, rather than header, (and so it is not inlined) , does it mean
that the scope for optimization is lost for inlining? If it is even
have a function call, how costly will it be (comparing to inlined
version) , given the fact it is a getter and thus do not have any
parameter list.
Those get functions return certain kind of container , which in turns
a class use to return a begin & end iterator for the container. ( i.e a
view class construct a pair of iterator with the help of original
container whose reference it holds, for certain range, and return).

推荐答案



toton ha scritto:

toton ha scritto:



因为内联不是mandetory,它取决于编译器内联某些

函数(或使用像fior GCC这样的开关),我的问题是有什么

内联函数未被声明为内联函数?

即编译器可能选择不内联某些内联函数,但是

它可以自由选择非内联函数内联它的函数?

我有一些简单的一行获取函数,而我想要内联的索引操作符是
。但是由于一些问题(比如我有一些循环

依赖,因此使用前向声明,因此不可能

在头文件中实现了一些get函数)。 />

其次,如果我在cpp

文件中构建一个带有getter函数的库,而不是标题,(并且它没有内联),它是否意味着

内联的优化范围丢失了吗?如果它甚至是
有一个函数调用,它的成本是多少(与内联的

版本相比),因为它是一个吸气剂,因此没有任何

参数列表。

这些获取函数返回某种容器,依次使用
a类来返回一个开始&结束容器的迭代器。 (即

视图类在原始

容器的帮助下构造一对迭代器,其容器的引用,对于特定范围和返回)。
Hi,
As inline is not mandetory, it depends on compiler to inline certain
function (or using switch like fior GCC), my question is there any
scope for inlining when it is not declared as inline function?
i.e compiler may choose not to inline certain inline function, but is
it free to choose a non inline function to inline it?
I have some simple one line get function, and index operators which I
want to get inlined. But due to some problem (like I have some circular
dependency, thus use forward declaration, and hence not possible to
have some get function implemented in header).

Secondly, If i build a library with the getter function in the cpp
file, rather than header, (and so it is not inlined) , does it mean
that the scope for optimization is lost for inlining? If it is even
have a function call, how costly will it be (comparing to inlined
version) , given the fact it is a getter and thus do not have any
parameter list.
Those get functions return certain kind of container , which in turns
a class use to return a begin & end iterator for the container. ( i.e a
view class construct a pair of iterator with the help of original
container whose reference it holds, for certain range, and return).



我认为大多数编译器会选择内联吗?一个函数本身,

他们不太关心内联关键字。他们通常不会b $ b内联。一个内联声明的函数,或者它们这样做即使你没有b $ b没有声明它是内联的。

I think that most compilers choose if "inline" a function by itself,
they don''t care much about the inline keyword. They often don''t
"inline" a function that is declared inline or they do so even if you
didn''t declare it inline.


Paolo写道:
Paolo wrote:

我认为大多数编译器会选择是否内联一个函数本身,

他们不太关心内联关键字。他们通常不会b $ b内联。一个内联声明的函数,即使你没有声明它是内联的,它们也会这样做。
I think that most compilers choose if "inline" a function by itself,
they don''t care much about the inline keyword. They often don''t
"inline" a function that is declared inline or they do so even if you
didn''t declare it inline.



此处的规则称为好像。


C ++标准据称用C ++编译器描述创建

特定种类的操作码。但是编译器可以自由地创建任何类型的b $ b b替代操作码,只要结果执行好像。编译器已经创建了指定的操作码。


所以编译器可能会以优化调用代码的方式内联函数,

无论哪个被调用的函数都是内联声明的。


-

Phlip
http://www.greencheese.us/ZeekLand < - 不是博客!!!

The rule here is called "as if".

The C++ Standard reputedly describes a C++ compiler in terms of creating
specific kinds of opcodes. But compilers are free to create any kind of
alternate opcodes so long as the results perform "as if" the compiler had
created the specified opcodes.

So a compiler might inline functions in ways that optimize the calling code,
regardless which called functions are declared inline.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!


toton写道:
toton wrote:



因为内联不是mandetory,它取决于编译器内联

某些

函数(或使用像fior GCC这样的开关),我的问题是,当没有声明为内联函数时,内联是否有任何

范围内联?

即编译器可能选择不内联某些内联函数,但

是否可以自由选择非内联函数来内联它?
Hi,
As inline is not mandetory, it depends on compiler to inline
certain
function (or using switch like fior GCC), my question is there any
scope for inlining when it is not declared as inline function?
i.e compiler may choose not to inline certain inline function, but
is
it free to choose a non inline function to inline it?



是的。只要可见的

效果相同,编译器就可以做任何想做的事情。你如何检测一个函数是否内联

或pot?

Yes. The compiler can do whatever it wants, as long as the visible
effect is the same. How would you detect whether a function is inlined
or pot?


我有一些简单的一行get函数和索引运算符



想要内联。但是由于一些问题(比如我有一些

循环依赖,因此使用前向声明,因此没有

可能在头文件中实现了一些get函数)。 />

其次,如果我在cpp

文件中构建一个带有getter函数的库,而不是标题,(并且它没有内联),它是否意味着

内联的优化范围丢失了吗?
I have some simple one line get function, and index operators which
I
want to get inlined. But due to some problem (like I have some
circular dependency, thus use forward declaration, and hence not
possible to have some get function implemented in header).

Secondly, If i build a library with the getter function in the cpp
file, rather than header, (and so it is not inlined) , does it mean
that the scope for optimization is lost for inlining?



这并不能阻止一些编译器进行内联。

That doesn''t stop some compilers from inlining anyway.


如果它甚至是

有函数调用,它的成本是多少(与内联的

版本相比),因为它是一个吸气剂,因此没有任何

参数列表。
If it is even
have a function call, how costly will it be (comparing to inlined
version) , given the fact it is a getter and thus do not have any
parameter list.



函数调用会花费更多。这有关系吗?


如果一行获取者需要两倍的时间,有人会注意到吗?

A function call will cost some more. Does it matter?

If a one line getter takes twice as long, will anyone notice?


这些获取函数返回某种容器,在

转动

a类使用返回开始&结束容器的迭代器。 (

ie

a视图类在原始

容器的帮助下构造一对迭代器,其容器的引用,在某个范围内,并返回)。
Those get functions return certain kind of container , which in
turns
a class use to return a begin & end iterator for the container. (
i.e
a view class construct a pair of iterator with the help of original
container whose reference it holds, for certain range, and return).



这里答案当然是无聊的它取决于。 :-)


对于某种具有迭代器的容器,没有一般的答案,

,其中某些函数可能被内联(或没有)。要获得真正的

结果,您必须尝试并测量它是否足够快。最多

经常是。

Bo Persson

Here the answer is of course the boring "It depends". :-)

There is no general answer for a kind of container with some iterator,
where some functions might get inlined (or not). To get the true
result, you have to try it out and measure if it is fast enough. Most
often it is.
Bo Persson


这篇关于内联问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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