Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3
This is the forum to discuss the Wrox book Beginning C# 3.0 : An Introduction to Object Oriented Programming by Jack Purdum; ISBN: 9780470261293
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 9th, 2009, 06:55 PM
Registered User
Points: 44, Level: 1
Points: 44, Level: 1 Points: 44, Level: 1 Points: 44, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2009
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default lvalue/rvalue vs. stack/heap

Mr.Purdum,

I appreciate for your kindly explanation through your nice book!

By the way, regarding lvalue and rvalue in the symbol table, I came to know some are expressing also as stack and heap, respectively.

How do these concepts relate each other?
Specifically, symbol table is a table, isn't it? And stack and heap may be specific memory allocation. Are these same?
  #2 (permalink)  
Old January 9th, 2009, 09:02 PM
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default

Hi Hkyoon:

The stack and the heap are two areas of memory that are actually controlled by Windows rather than Visual Studio. The stack usually starts at the top of high memory and grows downward as variables are allocated on the stack. As a general rule, variables that have automatic scope (e.g., variables defined within a method or parameters passed to a method) are allocated on the stack. When you exit the method, these auto variables go out of scope (i.e., die) and the stack is restored to its previous level. If you try to allocated too many variables on the stack, perhaps because of an ill-designed recursive piece of code or some data definition that takes place in a loop, it is possible to run out of stack space fairly quickly. (The stack is normally on 64K of memory...not sure if this is true under Vista.) The fix is to look at your algorithm, as it is probably faulty.

You can think of the heap as the rest of available memory that exists between the top of your program (within VIsual Studio) and the bottom of the stack. If you have lots of memory in your system, the heap is huge. All class method entry points, static data items, and non-automatic storage data types are stored in the heap space. If you create objects within a method, those objects are actually allocated on the heap rather than the stack. (See Figure 2-4, p.25). It's good practice to set such objects to null when you're done with them:

myFriend = null;

as this tells Window to make that chunk of memory available free for reuse (a process called Garbage Collection). While Visual Studio seems to do a great job of this now, that wasn't the case with earlier versions and the program could end with Windows thinking the memory was still in use. This is called a memory leak and, if you reran your program often enough, it was possible to run out of heap space.

Finally, the symbol table will use both stack and heap space, depending up on the scope of the data item being defined. With a few exceptions, auto scope variables are always on the stack while the others use the heap.

Hope this helps.

Dr. Purdum
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
  #3 (permalink)  
Old January 10th, 2009, 12:34 AM
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default

I did take a number of liberties in my explanation. When I said that the symbol table uses both stack and heap space, what I meant was that it tracks items allocated in both spaces...it would never itself be allocated on the stack. Also, I was pretty careful to say that setting an allocated object to null marks it for garbage collection. That is a process of Windows, not .Net or VS. Actually memory management for the system is always a task for Windows. While resources requests may go through .Net, Windows is ultimately responsible for the resource allocations. Also, my simplified explanation of Figure 2-4 and how memory is laid out treated the multiple processes controlled by VS as thought they were VS. Again, a simplification but true in concept if not in detail.

My software company produced C compilers back in the old MSDOS days and the internals of how the symbol table works and what it tracks is considerably more complex than I've explained here or in my book. (Indeed, the symbol table in the Eco-C88 C compiler tracked 32 attributes about each entry in the table.) However, after almost 30 years of teaching, I also know that throwing that much detail at a beginner is counter-productive, especially when the reader is just trying to get a grasp on the concepts. I stand by my simplified explanation here and think it will put the reader on the right track. Those interested in more detail can go to Amazon and look at various compiler design books (e.g., Steven Muchnick's book is good) available there if that's where their interest lie.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
  #4 (permalink)  
Old January 10th, 2009, 11:50 AM
Friend of Wrox
Points: 1,166, Level: 13
Points: 1,166, Level: 13 Points: 1,166, Level: 13 Points: 1,166, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 234
Thanks: 0
Thanked 32 Times in 30 Posts
Default

I think we are talking at cross purposes. However, the really sad thing is that poor Mr. Hkyoon has probably given up, gone away totally confused and taken up wood working instead.

Dr. Purdum
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
  #5 (permalink)  
Old January 11th, 2009, 11:17 PM
Friend of Wrox
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You are too right, and I am withdrawing my posts as being too far out in left field and irrelevant to this topic. I'll try to post such pedanticism in a more appropriate thread, from now on. With any luck, HKYoon will be able to ignore my non-posts.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
java.lang.OutOfMemoryError: Java heap space meetkotresh J2EE 1 February 2nd, 2008 01:52 AM
Heap of typing errors HELP!!! ours All Other Wrox Books 11 December 24th, 2007 11:23 AM
Heap Monitor pallavi11 VB How-To 5 January 11th, 2007 08:37 PM
Could not reserve enough space for object Heap overcit Apache Tomcat 0 February 23rd, 2006 12:11 PM
C++ Stack? Spivonious C++ Programming 6 October 11th, 2004 03:56 AM



All times are GMT -4. The time now is 01:51 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.