473,385 Members | 1,546 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,385 software developers and data experts.

heap and stack ?

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 this what's heap stack and what's the main difference
between those 2types ?

Nov 15 '05 #1
1 3739
The heap and the stack are the two places where programs store data (okay,
there are a few more, but they're the two most common ones).

The heap is just a big chunk of memory that is managed by a heap manager (or
garbage collector, in C#'s case). When you write something like:

Employee e = new Employee();

(assuming Employee is a class), you get a chunk of memory allocated out of
the heap to store the information for that employee instance. This instance
will be preserved until it isn't needed anymore (in C#), or until it is
explicitly deleted (in languages like C++).

The stack is used to hold local variables. So, when I write something like:

int i = 15;

as part of a method, that sets aside a chunk of space on the stack to hold
the value "15". When I enter a method, that space is used on the stack, and
when I leave the method, that space is reclaimed for later use.

To be strictly true, in my first example, I not only allocated an instance
of Employee on the heap, I allocated a reference to that on the stack.

Or, to be shorter, all local variables use up space on the stack. If they
are value types, this space is used to store the actual value. If they are
references types, this space is used as a reference (aka pointer) to the
actual value, which is stored on the heap.

Hope that helps.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
"Geiregat Jonas" <en***@sdf-eu.org> wrote in message
news:3f**********************@reader0.news.skynet. be...
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 this what's heap stack and what's the main difference
between those 2types ?

Nov 15 '05 #2

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; };
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...
3
by: nahur | last post by:
why do you need a heap and a stack why not all memory called a heap or call it a stack what is the purpose of having a heap and a stack
9
by: shine | last post by:
what is the difference between a heap and a stack?
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...
9
by: Roman Mashak | last post by:
Hello, I'm confused about heap and stack memories management in C language. Most books explain that local stack variables for each function are automatically allocated when function starts and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.