CG_INLINE,inline 内联函数
2012-08-18 21:25
399 查看
============================================================博文原创,转载请声明出处电子咖啡(原id蓝岩)============================================================内联函数,即在编译的时候将函数体替换函数调用,从而不需要将parameter,return address进行push/pop stack的操作,从而加速app的运行,然而,会增加二进制文件的大小。比如,再源码中:
inline int foo(int a, int b)
{
return a + b;
}
void bar(int a, int b)
{
NSLog(@"%d", foo(a, b));
}
编译过后成为:
void bar(int a, int b)
{
NSLog(@"%d", a + b);
}
问:内联函数和非内联函数有很大不同吗?
答:对硬件硬性不大,但在性能上有影响。
内联函数不能保证编译时候一定是内联的,内联仅仅是告诉编译器请求内联,但编译器不一定内联,比如再调用虚函数,递归(recursion),比如:
inline int aplusb_pow2(int a, int b) {
return (a + b)*(a + b) ;
}
for(int a = 0; a < 900000; ++a)
for(int b = 0; b < 900000; ++b)
aplusb_pow2(a, b);
CG_INLINE is a
inline int foo(int a, int b)
{
return a + b;
}
void bar(int a, int b)
{
NSLog(@"%d", foo(a, b));
}
编译过后成为:
void bar(int a, int b)
{
NSLog(@"%d", a + b);
}
问:内联函数和非内联函数有很大不同吗?
答:对硬件硬性不大,但在性能上有影响。
内联函数不能保证编译时候一定是内联的,内联仅仅是告诉编译器请求内联,但编译器不一定内联,比如再调用虚函数,递归(recursion),比如:
inline int aplusb_pow2(int a, int b) {
return (a + b)*(a + b) ;
}
for(int a = 0; a < 900000; ++a)
for(int b = 0; b < 900000; ++b)
aplusb_pow2(a, b);
CG_INLINE is a
#definefor
static inline. This causes the compiler to create the code for the function inline, rather that creating a function call on the stack. See here and here for more information.
相关文章推荐
- CG_INLINE,inline 内联函数
- CG_INLINE,inline 内联函数
- 从零开始学C++之从C到C++(二):引用、数组引用与指针引用、内联函数inline、四种类型转换运算符
- C++ inline constexpr 内联函数和常量表达式函数问题
- 6.2 Inline Method(内联函数)
- C语言中的内联函数(inline)与宏定义(#define)详细解析
- C++中的内联函数inline总结
- 浅析c++中的内联函数(关键字inline)
- 【C++】内联函数,inline
- 内联函数 —— C 中关键字 inline 用法解析
- C++内联函数(Inline)介绍
- C++内联函数(Inline)介绍
- 在C++语言中,关于内联函数(inline)的入门教程!
- 内联函数(inline)机制与陷阱
- C++内联函数(Inline)介绍
- 重构--Inline Method(内联函数),Inline Temp(内联临时变量),Substitute Algorithm(替换算法)(五)
- C语言内联函数inline
- >>fun=inline('exp(-x.*x)','x'); %用内联函数定义被积函数fname >>Isim=quad(fun,0,1) %辛普生法
- 理解内联函数inline在C++中的用法
- inline内联函数