Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 18th, 2005, 04:43 AM
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default urgent doubt between class & structure

hai,
 please clear my doubt. what it means (class is a reference type.structure is a value type)?.please any give a brief description about that.

 
Old February 18th, 2005, 09:12 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

Class is a reference type because it stores value(object) on the heap whereas
Structue( a value type) stores value on the stack.

 
Old February 23rd, 2005, 05:52 AM
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hai,
  thanks for ur kind reply.but i have doubt in ur reply.
what is difference b/w heap & stack(i think both r more or less same).i expect ur reply.

regards
geetha


 
Old February 23rd, 2005, 06:32 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

Heap: Regions located in kernel space from which memory blocks can be allocated and deallocated dynamically.
Stack : Stack is an area of memory for keeping temporary data.it uses LIFO algorithm.

Find below the differences b/w stack and heap
Stack:
- local variables (variables declared inside a function) are put on the stack - unless they are also declared as 'static' or 'register'
- function parameters are allocated on the stack
- local variables that are declared on the stack are not automatically initialized by the system so they usually have garbage in them until you set them
- variables on the stack disappear when the function exits (thus, if a function is called multiple times, it's local variables and parameters are recreated and destroyed each time the function is called end exited).

Heap:
- declared variables (as opposed to dynamically created ie new, malloc) are created on the heap before program execution begins, they exist the entire life of the program (although scope may prevent access to them - they still exist) and they are initialized to all zeros
- global variables are on the heap
- static local variables are on the heap (this is how they keep their value between function calls)
- memory allocated by new, malloc and calloc are on the heap





 
Old February 23rd, 2005, 06:39 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

You can visit this site to know about more
http://www.cs.umd.edu/~mvz/cmsc330-s02/slides/9-1.pdf

 
Old February 24th, 2005, 09:27 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

every reference type(class) has two sections
1-a pointer to the instansiated object(to heap) is put on stack
2-the instantiated object is created on heap
every value type(struct) just is put on the stack ,
and stack is much faster than heap so bigger data is created on the heap.

_____________
Mehdi.
software student.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to build class structure for collection output jimusa Visual Basic 2005 Basics 3 August 7th, 2008 04:49 PM
doubt in XSLT -- very urgent subbukns XSLT 1 May 21st, 2007 05:10 PM
Very urgent, Doubt in ASP ssramvinay Classic ASP Databases 1 April 17th, 2007 01:21 PM
Doubt in clone Method of Object Class pandian Java Basics 1 October 12th, 2006 03:29 PM
very very urgent doubt spec in c#.net geetha VS.NET 2002/2003 0 December 21st, 2005 07:29 AM





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