467,210 Members | 1,285 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

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

Heap, stack, pile?

Someone at work asked me this question:

Value types--do they hit the heap or the pile? Well, I was a bit
dumbfounded, because I never heard of the term "pile". I've heard of
heap and stack, but what is a pile? Is it just another name for
stack? Doing some reading, I found that value types use stack memory
since the size can be determined at compile time and there's less
overhead with this type of memory. So, I'm thinking this is just
another name for stack. I couldn't find "pile" defined in
webopaedia.com.

Comments appreciated.

Thanks in advance!
Nov 16 '05 #1
  • viewed: 3002
Share:
4 Replies
Robbie,

I've never heard of pile, but I would assume that it means "stack".

With value types, if you declare them in a method, then they are on the
stack. If they are fields in a class, then those are on the heap, because
the instance of the class itself is on the heap.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Robbie" <Ro************@netscape.net> wrote in message
news:17**************************@posting.google.c om...
Someone at work asked me this question:

Value types--do they hit the heap or the pile? Well, I was a bit
dumbfounded, because I never heard of the term "pile". I've heard of
heap and stack, but what is a pile? Is it just another name for
stack? Doing some reading, I found that value types use stack memory
since the size can be determined at compile time and there's less
overhead with this type of memory. So, I'm thinking this is just
another name for stack. I couldn't find "pile" defined in
webopaedia.com.

Comments appreciated.

Thanks in advance!

Nov 16 '05 #2
Robbie <Ro************@netscape.net> wrote:
Someone at work asked me this question:

Value types--do they hit the heap or the pile? Well, I was a bit
dumbfounded, because I never heard of the term "pile". I've heard of
heap and stack, but what is a pile? Is it just another name for
stack? Doing some reading, I found that value types use stack memory
since the size can be determined at compile time and there's less
overhead with this type of memory. So, I'm thinking this is just
another name for stack. I couldn't find "pile" defined in
webopaedia.com.


I haven't heard of "pile" either, to be honest.

Value types reside on the stack if they come from:
o Local variables
o Intermediate expressions (i.e. evaluation on the stack)
o Instance variables where the enclosing value is also on the stack

See http://www.pobox.com/~skeet/csharp/memory.html for more
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
In other words if the value type is part of the state of a reference type it gets allocated on the managed pile ... sorry heap ... inline with the rest of that object's state.

e.g.

struct Point

{

int x;

int y;

}

class Line

{

Point start;

Point end;

}

The memorry for the Point instances will be allocated on the managed heap when a line instance is created.

Regards

Richard Blewett - DevelopMentor

http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<MP************************@msnews.microsoft.com >

Robbie <Ro************@netscape.net> wrote:
Someone at work asked me this question:

Value types--do they hit the heap or the pile? Well, I was a bit
dumbfounded, because I never heard of the term "pile". I've heard of
heap and stack, but what is a pile? Is it just another name for
stack? Doing some reading, I found that value types use stack memory
since the size can be determined at compile time and there's less
overhead with this type of memory. So, I'm thinking this is just
another name for stack. I couldn't find "pile" defined in
webopaedia.com.


I haven't heard of "pile" either, to be honest.

Value types reside on the stack if they come from:
o Local variables
o Intermediate expressions (i.e. evaluation on the stack)
o Instance variables where the enclosing value is also on the stack

See http://www.pobox.com/~skeet/csharp/memory.html for more
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10/09/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #4
Richard Blewett [DevelopMentor] <ri******@develop.com> wrote:
In other words if the value type is part of the state of a reference
type it gets allocated on the managed pile ... sorry heap ... inline
with the rest of that object's state.


Exactly. This is why I disagree when people just say "Reference types
are allocated on the heap. Value types are allocated on the stack" and
leave it at that.

I must get round to writing my "definitive guide to reference vs value
types" some time :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Kevin Grigorenko | last post: by
17 posts views Thread by Jonas Rundberg | last post: by
1 post views Thread by Geiregat Jonas | last post: by
9 posts views Thread by shine | last post: by
2 posts views Thread by Ganesh | last post: by
24 posts views Thread by arcticool@hotmail.com | last post: by
16 posts views Thread by sarathy | last post: by
53 posts views Thread by fdmfdmfdm@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.