What is the difference between heap and stack

V

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
 
M

Moonlit

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
 
M

Moonlit

--


Regards, Ron AF Greve

http://moonlit.xs4all.nl

Moonlit said:
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
 
M

Moonlit

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).
 
M

Mark P

Moonlit said:
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
 
K

Kai-Uwe Bux

"Moonlit" <news moonlit xs4all nl> wrote:

[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.
 
D

David Harmon

On Thu, 14 Sep 2006 02:03:40 +0200 in comp.lang.c++, "Moonlit" <news
moonlit xs4all nl> wrote,
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.mccaughan/g/remarks/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
 
K

Kaz Kylheku

Moonlit said:
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?
 
J

jmcgill

Kaz said:
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.
 
D

Default User

Moonlit said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top