473,402 Members | 2,055 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,402 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 6191
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
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...

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.