473,244 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,244 software developers and data experts.

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 6181
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
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...
7
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...
24
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...
5
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...
43
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...
2
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. ...
28
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. ...
53
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...
350
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.