Chinaunix首页 | 论坛 | 博客
  • 博客访问: 773735
  • 博文数量: 37
  • 博客积分: 575
  • 博客等级: 中士
  • 技术积分: 320
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-12 10:43
个人简介

活到老,学到老!

文章分类

全部博文(37)

文章存档

2019年(4)

2018年(4)

2015年(1)

2014年(14)

2011年(1)

2010年(13)

我的朋友

分类: C/C++

2019-04-12 10:04:29

发现做了这么多年的嵌入式开发,还有朋友搞不清楚stack & heap的区别,在阅读《Operating Systems_Three Easy Piece》时,里面的一段解释觉得非常好!
C programs use the stack for local variables, function parameters, and return addresses; the OS allocates this memory and gives it to the process. The OS will also likely initialize the stack with arguments; specifically, it will fill in the parameters to the main() function, i.e., argc and the argv array .
stack用于变量、函数参数、函数返回地址;

In C programs, the heap is used for explicitly requested dynamically-allocated data; programs request such space by calling malloc() and free it explicitly by calling free(). The heap is needed for data structures such as linked lists, hash tables, trees, and other interesting data structures. The heap will be small at first; as the program runs, and requests more memory via the malloc() library API, the OS may get involved and allocate more memory to the process to help satisfy such calls.
heap用于程序动态分配数据,比如malloc(),分配数据类型等,heap随着程序运行会分配越来越多的存储空间。

阅读(204498) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~