Re: Question about value types

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Zach (nuts_at_to.spammers)
Date: 02/12/05


Date: Sat, 12 Feb 2005 11:22:37 +0100


"Bruce Wood" <brucewood@canada.com> wrote in message
news:1108166765.721830.324550@g14g2000cwa.googlegroups.com...
<snipped>

I compiled the following text - would you agree with this text?

Variables and constants are storage locations with names. A constant is a
variable with a continuous value. A "read only" variable is a constant.
Variables can be classified in terms of location, size, scope, type, value,
duration (the time span during which they have a life) and how their value
is retrieved. Variables can be located on the heap or on the stack. The size
of the storage location is independent of the compiler or the operating
system, but is determined by their type (e.g. int, double). Scope and
duration are determined by where the variable is declared. Variables
declared in a method - or in the parameter list of a method - are local
variables. They have no life outside the method. Parameters can be straight
values, or additionally qualified as "out" (returns a value), or "ref"
(changes the value). The value of a variable can be numerical or
alpha-numerical (i.e. a string value). Variables like int are called
"intrinsic", or (=) "built-in" or (=) "primitive" types. Primitive types are
structs. Which means that all variable in C# are objects. The value of a
variable is retrieved directly from the stack ("value types"), or indirectly
via a pointer ("reference types"). Pointers represent values, which
themselves cannot be approached ditectly. Because of this difference value
types are more efficient. Pointers are stored on the stack, whereas the
values they represent are stored on the heap. A variable declared in an
object is stored together (some authors say "inline") with that object. For
example a system array refers to a contiguous block of memory on the heap,
large enough to hold the number and type of elements for which it was
declared. Its pointers are on the stack; its values are on the heap. But in
the case of an array of reference types, there are pointers on the stack -
to pointers on the heap - pointing to values on the heap.



Relevant Pages