堆和堆栈有什么区别 [英] What is the difference between heap and stack

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

问题描述



任何人都可以告诉我堆内存和堆栈堆栈之间的区别

从物理上和根本上来说。这将是一个真正的好处。


问候,

Veeru

Hi,
Can anyone tell me the difference between heap memory and stack stack
both physically and fundamentally. It would be a real favour.

Regards,
Veeru

推荐答案

Veeru写道:
Veeru wrote:

任何人都可以告诉我堆内存和堆栈堆栈之间的区别

从物理上和根本上来说。这将是一个真正的好处。请b
Can anyone tell me the difference between heap memory and stack stack
both physically and fundamentally. It would be a real favour.

www.google.com





编译C ++程序的一个非常简单的视图(假设x86机器

32有点视觉C ++(但我想Borland也会这样做)


func(长A)

{

长B;

长* C =新长;

}


调用func时会发生什么:

func的调用者在堆栈上推送A

func的调用者实际上通过ML''call''操作调用func,这会推动

返回地址堆栈

通常输入Func它会构建一个堆栈帧(即它将ebp推到

,堆栈将当前堆栈指针存储到ebp寄存器中并生成

用于本地堆栈的空间(自动变量)即它将从esp寄存器中获取
substreact 8(4为B,4为C指针不为

也指出了)


接下来执行''new long''这将搜索几个字节的免费

内存在一个独立的内存部分(即不是堆)这个

内存的地址存储在C中,即堆栈上。\


当func退出时,它将清理构建堆栈框架即用ebp加载esp

和堆栈的pop ebp

离开func之后,调用者将向esp添加4以摆脱A的空间


(注意x86实际上更适合于使用的pascal调用约定

例如在ms-windows中,这里被调用的函数也将esp调整为

摆脱了A的空间。在ml x86中,这可以通过一条指令完成

''ret 4'')

-

问候,Ron AF Greve

http://moonlit.xs4all。 nl


" Veeru" < va ****** @ gmail.comwrote in message

news:11 ********************* @ e3g2000cwe。 googlegrou ps.com ...
Hi,

A very simple view of a part of a compiled C++ program (assuming x86 machine
32 bit visual C++ (but I guess borland would do the same)

func( long A )
{
long B;
long *C = new long;
}

What happens when func gets called:

Caller of func pushes A on the stack
Caller of func actually calls func by ML ''call'' operation this pushes the
return address on the stack
Func is entered typically it builds a stack frame (i.e. it pushes ebp onto
the stack stores the current stack pointer into the ebp register and makes
room on the stack for the local (automatic variables) That is it will
substreact 8 from the esp register (4 for B and 4 for C pointer not for the
pointed too)

Next the ''new long'' is executed this will search for a few bytes of free
memory in a separate part of memory (i.e. not the heap) the address for this
memory is stored in C i.e. on the stack.\

When func exits it will cleanup the build stack frame i.e load esp with ebp
and pop ebp of the stack
After leaving func the caller will add 4 to esp to get rid of the room for A

(note the x86 is actually more optimised for pascal calling convention used
for instance in ms-windows, here the called function also adjust the esp to
get rid of the room for A. In ml x86 this can be done with one instruction
''ret 4'' )
--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Veeru" <va******@gmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...



谁能告诉我堆内存和堆栈之间的区别

身体上和根本上。这将是一个真正的好处。


问候,

Veeru
Hi,
Can anyone tell me the difference between heap memory and stack stack
both physically and fundamentally. It would be a real favour.

Regards,
Veeru






-

问候,Ron AF Greve

http://moonlit.xs4all.nl

Moonlit < news moonlit xs4all nlwrote in message

news:45 ********************** @ news.xs4all.nl ...


--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Moonlit" <news moonlit xs4all nlwrote in message
news:45**********************@news.xs4all.nl...




编译C ++程序的一个非常简单的视图(假设x86

机器32位可视化C ++(但我想Borland会做同样的事情)


func(长A)

{

长B;

长* C =新长;

}


调用func时会发生什么:


func的调用者在堆栈上推送A

func的调用者实际上通过ML''call''操作调用func这推动了

栈上的返回地址

输入Func通常会构建一个堆栈帧(即它将ebp推到

,堆栈将当前堆栈指针存储到ebp寄存器中并生成

本地堆栈上的空间(自动变量)也就是说它将从esp寄存器中获取
substreact 8(B为4,C指针为4)对于

指针也是如此)


接下来执行''new long''将搜索几个字节的免费
$ b内存的单独部分中的$ b内存
Hi,

A very simple view of a part of a compiled C++ program (assuming x86
machine 32 bit visual C++ (but I guess borland would do the same)

func( long A )
{
long B;
long *C = new long;
}

What happens when func gets called:

Caller of func pushes A on the stack
Caller of func actually calls func by ML ''call'' operation this pushes the
return address on the stack
Func is entered typically it builds a stack frame (i.e. it pushes ebp onto
the stack stores the current stack pointer into the ebp register and makes
room on the stack for the local (automatic variables) That is it will
substreact 8 from the esp register (4 for B and 4 for C pointer not for
the pointed too)

Next the ''new long'' is executed this will search for a few bytes of free
memory in a separate part of memory



--->(即不是堆)

对不起意思''我,e,不是堆栈':-(

这个地址


内存存储在C中,即存储在堆栈中。\


当func退出时,它将清理构建堆栈帧,即加载esp与

ebp和pop ebp的堆栈

离开func之后,调用者将添加4到esp以摆脱房间

A

(注意x86实际上更适合于pascal调用约定

例如在ms-windows中使用,这里被调用的函数也调整了

esp到摆脱A的空间。在ml x86中,这可以用一个

指令''ret 4''完成。


-


问候,Ron AF Greve

http: //moonlit.xs4all.nl


" Veeru" va ****** @ gmail.comwrote in message

新闻:11 ***************** **** @ e3g2000cwe.googlegrou ps.com ...
memory is stored in C i.e. on the stack.\

When func exits it will cleanup the build stack frame i.e load esp with
ebp and pop ebp of the stack
After leaving func the caller will add 4 to esp to get rid of the room for
A

(note the x86 is actually more optimised for pascal calling convention
used for instance in ms-windows, here the called function also adjust the
esp to get rid of the room for A. In ml x86 this can be done with one
instruction ''ret 4'' )
--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Veeru" <va******@gmail.comwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...

>
任何人都可以告诉我堆内存和堆栈之间的区别
身体上和根本上。这将是一个真正的好处。

问候,
Veeru
>Hi,
Can anyone tell me the difference between heap memory and stack stack
both physically and fundamentally. It would be a real favour.

Regards,
Veeru




这篇关于堆和堆栈有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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