当前位置:网站首页>Parameter stack pressing problem of C language in structure parameter transmission
Parameter stack pressing problem of C language in structure parameter transmission
2022-04-23 14:25:00 【KissKernel】
First, in memory , It is divided into three areas , The stack area , Heap area , And static area . Local variables are stored in the stack area , Shape parameter , And the space opened up by function calls . Heap area is mainly about dynamic memory allocation . The static area is mainly used to store global variables and static variables .
The problem of parameter stack pressing is put forward in the place of structure parameter transmission ,c When a function passes parameters in a language , Parameters need to be stacked . If you pass a structure object, the structure is too large , The system overhead of parameter stack pressing is too high , Performance will decline . It involves the creation and destruction of function stack frames .
The following reference takes simple code as an example
#include<stdio.h>
int add(int x, int y)
{
int z = 0;
z = x + y;
return z;
}
int main()
{
int a = 20, b = 10;
int ret = 0;
ret = add(a, b);
return 0;
}
The code is abstracted in memory as shown in the figure

b Pass the reference to y It is equivalent to copying a copy in the stack area b.c It's the same thing . This is just passing a variable to the function , If b Become a structure , Because the structure is too large, it will consume too much memory in the stack area , Performance degradation . We usually use the method of address transmission .
版权声明
本文为[KissKernel]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231412252056.html
边栏推荐
- js 进度条,显示加载进度
- 单相交交变频器的Matlab Simulink建模设计,附Matlab仿真、PPT和论文等资料
- API Gateway/API 网关(二) - Kong的使用 - 负载均衡Loadbalance
- Flop effect
- c语言在结构体传参时参数压栈问题
- 时间复杂度计算举例
- Thread group ThreadGroup uses introduction + custom thread factory class to implement threadfactory interface
- MySQL同步Could not find first log file name in binary log index file错误
- 数组模拟队列进阶版本——环形队列(真正意义上的排队)
- 常见存储类型和FTP主被动模式解析
猜你喜欢
随机推荐
How does void * exist?
八路抢答器系统51单片机设计【附Proteus仿真、C程序、原理图及PCB文件、元器件清单和论文等】
js 抛物线运动方法封装
c语言在结构体传参时参数压栈问题
ansible及常用模块的使用
如何5分钟上手使用OCR
SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
C语言知识点精细详解——初识C语言【1】
OpenFaaS实战之四:模板操作(template)
51单片机+LCD12864液晶显示的俄罗斯方块游戏,Proteus仿真、AD原理图、代码、论文等
本以为能躺着进华为,结果陆续收到京东/滴滴/爱奇艺offer的我迷茫了
操作系统常见面试题目:
Flop effect
C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【2】
直流可调稳压电源的Proteus仿真设计(附仿真+论文等资料)
Gif to still image processing
Sed learning for application
DP - [noip2000] grid access
Web page, adaptive, proportional scaling
Upgrade of openssh and modification of version number









