468,491 Members | 2,009 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

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 5874
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*********************@e3g2000cwe.googlegrou ps.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*********************@e3g2000cwe.googlegrou ps.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.com/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.com/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
Moonlit wrote:
I like to toppost so you don't have to scroll all the way down (personally I
really hate that).
Nobody cares what you personally like or dislike. Personally, I prefer
driving on the right side of the road. Try explaining that to a police
officer in Japan.

Having to scroll all the way down is a symptom of another breach of
netiquette: the author has quoted way too much material before starting
the first original line of text.

I don't like top posting, but I do it in my work correspondence,
because that's how it's done by users of Outlook and Exchange.
Why do you think replies 'belong following or interspersed'?
One reason is that it's the way it has been done on Usenet since before
1980. There are other reasons, of course, but that's a very good good
one.

A second reason is consistency. If everyone follows the same
conventions, it's better than if conventions are randomly patched on
top of each other in a chain of replies, with each nesting level
defining its own flow order. The article as a whole, regardless of how
many levels of quoting it contains, should flow in one direction, be it
bottom to top, or top to bottom.

One benefit to consistency is that software can parse the structure of
an article body and render its structure in alternate ways. Some of the
things good news reading software can do is fold up the quoted text, or
automatically jump to the first piece of original text so that no
scrolling is required to begin reading.

Interspersing of replies is necessary in order to associate related
points together by proximity and flow direction. For instance, here it
is obvious that my three paragraphs pertain to the "Why do you
think..." sentence above, because they are inserted beneath it.
Top-posting e-mail or forum cultures never seem to have a
well-developed way of doing this. People switch to interspersed
replying when they want to address specific points.
Let everyone post the way they like, think about freedom instead of imposing
your will on others.
This is a newsgroup related to computer programming. Is this your
attitude in team programming also? Everyone on the team follow his own
conventions? That's one way code turns into tossed salad.
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).
So you'd rather be killfiled for failing to follow some simple
conventions than to follow them?

Sep 14 '06 #11
Kaz Kylheku wrote:
I don't like top posting, but I do it in my work correspondence,
because that's how it's done by users of Outlook and Exchange.
Business correspondence has been LIFO stacks, probably since before
typewriters. When in Rome, etc.
Sep 14 '06 #12
Moonlit wrote:
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).
That's only when others are also violating netiquette. Notice that my
message said "properly trimmed quotes".

You've received plenty of explanation from other responders.
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).
That will depend on whether you "see the light" or not.

Brian
Sep 14 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Ravi Tallury | last post: by
5 posts views Thread by bull | last post: by
43 posts views Thread by Mountain Bikn' Guy | last post: by
53 posts views Thread by fdmfdmfdm | last post: by
350 posts views Thread by Lloyd Bonafide | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.