473,804 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is the difference between heap and stack

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

Sep 13 '06 #1
12 6225
Veeru wrote:
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, please.
Sep 13 '06 #2
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******** *************@e 3g2000cwe.googl egroups.com...
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

Sep 13 '06 #3


--
Regards, Ron AF Greve

http://moonlit.xs4all.nl

"Moonlit" <news moonlit xs4all nlwrote in message
news:45******** **************@ news.xs4all.nl. ..
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)
sorry meant 'i,e, not the stack' :-(
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******** *************@e 3g2000cwe.googl egroups.com...
>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


Sep 13 '06 #4
Moonlit wrote:
Hi,
Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.c om/c++-faq-lite/how-to-post.html>

Brian
Sep 13 '06 #5
Veeru wrote:
Hi,
Can anyone tell me the difference between heap memory and stack stack
both physically and fundamentally. It would be a real favour.
Look in the nice textbook on operating systems, or computer
architecture or what have you on your computer science bookshelf.

Here is another idea, also:

http://www.justfuckinggoogleit.com/s...p+stack+memory

Sep 13 '06 #6
Hi,

I didn't see anything about top posting there actually.

I like to toppost so you don't have to scroll all the way down (personally I
really hate that).

Why do you think replies 'belong following or interspersed'?

Let everyone post the way they like, think about freedom instead of imposing
your will on others.

Regards, Ron AF Greve

http://moonlit.xs4all.nl

PS: You can probably add me to your kill list or just don't read my posts
(and really you don't have to tell me that you did).

"Default User" <de***********@ yahoo.comwrote in message
news:4m******** ****@individual .net...
Moonlit wrote:
>Hi,

Please don't top-post. Your replies belong following or interspersed
with properly trimmed quotes. See the majority of other posts in the
newsgroup, or the group FAQ list:
<http://www.parashift.c om/c++-faq-lite/how-to-post.html>

Brian

Sep 13 '06 #7
Moonlit wrote:
Hi,

I didn't see anything about top posting there actually.
Read item 5.4 again.
>
I like to toppost so you don't have to scroll all the way down (personally I
really hate that).

Why do you think replies 'belong following or interspersed'?
By more or less general consensus, this is considered good etiquette by
this newsgroup. Obviously USENET is a (mostly) free entity and you can
do what you want, but it would be polite to respect established conventions.

From a more practical point of view, because USENET threads tend to
resemble conversations between multiple parties, where one often
responds (and responds and responds) to earlier posts, interspersed
replies maintain the chronological order of the discussion. And if one
wants to respond to a _particular section_ of a prior post, such as I
have done above in response to your claim not to have seen anything
about top posting in the FAQ, then there's really no sensible place to
do so except immediately after the section of interest.

Mark
Sep 14 '06 #8
"Moonlit" <news moonlit xs4all nlwrote:

[snip]
I didn't see anything about top posting there actually.
It's at the end of 5.4.

I like to toppost so you don't have to scroll all the way down (personally
I really hate that).

Why do you think replies 'belong following or interspersed'?
Because, that makes it clear what you are replying to. See also the PS.

Let everyone post the way they like, think about freedom instead of
imposing your will on others.
[snip]

It's a cultural (and very much local) thing. In this news group, the culture
is that top posting is frowned upon. Of course, the regulars cannot stop
you, but they can (and will) correct you more or less every time. At some
point, they might decide to kill-file you. As a matter of fact, some
regulars feel rather strongly about this issue.
Best

Kai-Uwe Bux
PS: A top post version of my reply your have been. You may want to check if
it is really easy to see what it is that I reply to:

It's at the end of 5.4.

Because, that makes it clear what you are replying to. See also the PS.

It's a cultural (and very much local) thing. In this news group, the culture
is that top posting is frowned upon. Of course, the regulars cannot stop
you, but they can (and will) correct you more or less every time. At some
point, they might decide to kill-file you. As a matter of fact, some
regulars feel rather strongly about this issue.
>I didn't see anything about top posting there actually.

I like to toppost so you don't have to scroll all the way down (personally
I really hate that).

Why do you think replies 'belong following or interspersed'?

Let everyone post the way they like, think about freedom instead of
imposing your will on others.
Sep 14 '06 #9
On Thu, 14 Sep 2006 02:03:40 +0200 in comp.lang.c++, "Moonlit" <news
moonlit xs4all nlwrote,
>Why do you think replies 'belong following or interspersed'?
"If you are sending a reply to a message or a posting be sure you
summarize the original at the top of the message, or include just
enough text of the original to give a context."
-- From RFC1855, http://sunsite.dk/RFC/rfc/rfc1855.html page 8

how do I quote correctly in usenet?
http://www.netmeister.org/news/learn2quote2.html
the advantages of usenet's quoting conventions
http://web.ukonline.co.uk/g.mccaugha...ks/uquote.html
why bottom-posting is better than top-posting
http://fmf.fwn.rug.nl/~anton/topposting.html
"rules" for posting to usenet:
http://www.faqs.org/faqs/usenet/posting-rules/part1/
Bottom vs. top posting and quotation style on Usenet
http://www.cs.tut.fi/~jkorpela/usenet/brox.html
zen and the art of the internet (usenet section)
http://www.cs.indiana.edu/docproject/zen/zen-1.0_6.html
What do you mean "my reply is upside-down"?
http://www.i-hate-computers.demon.co.uk/
Posting help for newbies
http://www.windfalls.net/ukrm/postinghelp.html
Ken Robbins - Quoting on Usenet
http://members.home.net/krobb7/quoting.html
Sep 14 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6818
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what the issue is. Thanks Ravi
7
17002
by: wwj | last post by:
Hi ,all I want to know the difference between char a and char *p=new char and the difference between the heap and the stack ,and if the char a is corresponding to the stack in MEMORY,and char *p=new char is corresponding to the heap of MEMORY. Give me some hint. THANK YOU.
24
3638
by: wwj | last post by:
Hi ,all I want to know the difference between char a and char *p=new char and the difference between the heap and the stack ,and if the char a is corresponding to the stack in MEMORY,and char *p=new char is corresponding to the heap of MEMORY. Give me some hint. THANK YOU.
5
7018
by: bull | last post by:
hi could any one explain with example the following in a better way to understand 1. what is stack in memory, how the programs are stored in stack , what is the use of stack 2. What is heap in memory, how the programs are stored in heap , what is the use of heap 3. what is pool memory otherwise memory pool, what is the use of memory pool 4. what is difference between stack and heap
43
6905
by: Mountain Bikn' Guy | last post by:
I have a situation where an app writes data of various types (primitives and objects) into a single dimensional array of objects. (This array eventually becomes a row in a data table, but that's another story.) The data is written once and then read many times. Each primitive read requires unboxing. The data reads are critical to overall app performance. In the hopes of improving performance, we have tried to find a way to avoid the...
2
13751
by: Ma Xiaoming | last post by:
Dear ladies and gentlemen, I don't understand what the difference between the Heap and the Stack is. Could you please explain the difference between the both for me? Thank you very much. Best regards.
28
4650
by: Dennis | last post by:
I have a function which is called from a loop many times. In that function, I use three variables as counters and for other purposes. I can either use DIM for declaring the variables or Static. Would the performance be better using Static versus Dynamic. I would think it would be quicker with STATIC declarations since the variables would only have to be created once. Can anyone confirm this. Thanks. -- Dennis in Houston
53
26412
by: fdmfdmfdm | last post by:
This is an interview question and I gave out my answer here, could you please check for me? Q. What are the memory allocation for static variable in a function, an automatic variable and global variable? My answer: static variable in function and global variable are allocated in head, and automatic variable is allocated in stack. Right?
350
11951
by: Lloyd Bonafide | last post by:
I followed a link to James Kanze's web site in another thread and was surprised to read this comment by a link to a GC: "I can't imagine writing C++ without it" How many of you c.l.c++'ers use one, and in what percentage of your projects is one used? I have never used one in personal or professional C++ programming. Am I a holdover to days gone by?
0
10101
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9177
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6870
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3837
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3005
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.