当前位置:网站首页>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
边栏推荐
猜你喜欢
C语言知识点精细详解——数据类型和变量【2】——整型变量与常量【1】
API Gateway/API 网关(二) - Kong的使用 - 负载均衡Loadbalance
Multisim Simulation Design of DC adjustable regulated power supply of LM317 (with simulation + paper + reference)
一篇博客让你学会在vscode上编写markdown
Qt实战:云曦日历篇
AT89C51单片机的数字电压表开发,量程0~5V,proteus仿真,原理图PCB和C程序等
金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)
Nacos作为配置中心(四) 使用Demo
setcontext getcontext makecontext swapcontext
API Gateway/API 网关(四) - Kong的使用 - 集成Jwt和熔断插件
随机推荐
Qt实战:云曦聊天室篇
循环队列的基本操作,你学会了吗?
SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
js 进度条,显示加载进度
Qt界面优化:Qt去边框与窗体圆角化
Introduction to loan market quotation interest rate (LPR) and loan benchmark interest rate
浅谈skiplist在LevelDB的应用
TLS/SSL 协议详解 (28) TLS 1.0、TLS 1.1、TLS 1.2之间的区别
微信小程序将原生请求通过es6的promise来进行优化
时间复杂度计算举例
MQ-2和DS18B20的火灾温度-烟雾报警系统设计,51单片机,附仿真、C代码、原理图和PCB等
js 格式化时间
字节面试编程题:最小的K个数
C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【2】
Nacos uses demo as configuration center (IV)
顺序表的操作,你真的学会了吗?
Docker篇 (五) MySQL的安装
Matlab Simulink modeling and design of single-phase AC-AC frequency converter, with MATLAB simulation, PPT and papers
js 递归(1)
逻辑卷创建与扩容