472,378 Members | 1,219 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

Similar topics

14
by: Kevin Grigorenko | last post by:
Hello, I couldn't find an obvious answer to this in the FAQ. My basic question, is: Is there any difference in allocating on the heap versus the stack? If heap or stack implementation is not...
17
by: Jonas Rundberg | last post by:
Hi I just started with c++ and I'm a little bit confused where stuff go... Assume we have a class: class test { private: int arr; };
1
by: Geiregat Jonas | last post by:
I'm reading Eric Gunnerson's book. He is talking about the heap and stack, he says you have 2types, value wich are in the stack or inline or reference types wich are in the heap. I don't get...
2
by: Nick McCamy | last post by:
I have a question related to allocating on the stack. In this program below, are my following assumptions true? - variable a is allocated on the heap since it's static - variable b is...
9
by: shine | last post by:
what is the difference between a heap and a stack?
2
by: Ganesh | last post by:
I am not sure if this question is relevant here. Why is 'heap' (the place where dynamic memory allocation occurs) called so? There is also a data structure called 'heap'. What is the connection? ...
24
by: arcticool | last post by:
I had an interview today and I got destroyed :( The question was why have a stack and a heap? I could answer all the practical stuff like value types live on the stack, enums are on the stack, as...
16
by: sarathy | last post by:
Hi all, I need a few clarifications regarding memory allocaion in C++. I apologize for the lengthy explanation. 1. In C++, Objects are allocated in heap. What does heap refer to? Is it an area...
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.