Heap, stack, pile?

R

Robbie

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!
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
J

Jon Skeet [C# MVP]

Robbie said:
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.
 
R

Richard Blewett [DevelopMentor]

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/<[email protected]>

Robbie said:
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 - <[email protected]>
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]
 
J

Jon Skeet [C# MVP]

Richard Blewett said:
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 :)
 

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

Top