Memory Location

  • Thread starter Thread starter rn5a
  • Start date Start date
R

rn5a

Is it possible to practically see the memory location stored in a
variable? For e.g. consider the statement

Dim myInt As Integer = 10

If I am not wrong, the memory location allocated to "myInt" would
store the value of 10. Is it possible to see where exactly has the
memory been allocated & what is the value at that memory location?

I doubt if I have expressed myself lucidly.....I am asking this
question in the hope that it would help me understand reference
types.....right now, I am getting too confused after going through a
plethora of articles on reference types....

Thanks,

Ron
 
You could likely with a low level debugger but I'm not sure this would help
to grasp the concepts.

You could start by :
- Keep in mind (but only for a short period of time !) that a variable name
is just a "symbol" for a memory location
- For a value type, the value is stored at this memory location.
- For a reference type, the value stored at this location is the location
(i.e. a pointer or a "reference") of the actual object.

Now as precisely the goal of a variable is to keep us away from having to
deal with the concept of memory locations, we'll simply say that the value
is stored "in" the variable and the variable name is thought as the value
that is stored at this location (rather than its location itself).

This is perhaps where the confusion could arise.

Hoping to decrease rather than to increase your confusion...
 
You could likely with a low level debugger but I'm not sure this would help
to grasp the concepts.

You could start by :
- Keep in mind (but only for a short period of time !) that a variable name
is just a "symbol" for a memory location
- For a value type, the value is stored at this memory location.
- For a reference type, the value stored at this location is the location
(i.e. a pointer or a "reference") of the actual object.

Now as precisely the goal of a variable is to keep us away from having to
deal with the concept of memory locations, we'll simply say that the value
is stored "in" the variable and the variable name is thought as the value
that is stored at this location (rather than its location itself).

This is perhaps where the confusion could arise.

Hoping to decrease rather than to increase your confusion...

--
Patrice
.
<[email protected]> a écrit dans le message de (e-mail address removed)...







- Show quoted text -

Patrice, it has indeed been very nice of you to help me grasp the
topic of reference types. Thanks for the same. However I am extremely
sorry to confess that your answer has further compounded my
confusions.

I guess I need a break, think peacefully about it & come afresh
tomorrow with a fresh mind....so see you tomorrow......

Ron
 
Was afraid of that as I was not sure what caused the confusion.

The thing you'll see most often is :
- a variable stores something
- a value type is a type whose data are stored directly by this variable
- a reference type is a type whose data are stored as a reference (a
pointer) to the actual data

For example an integer will be directly stored in the variable (this is a
value type).
On the other hand an object (whose size can vary much, that have methods
etc...) is actually a reference (a pointer) on the actual data that allows
to implements such a behavior.


I wanted to mention that a variable name is basically itself an alias for a
storage location thinking that it could be what caused this confusion...

Hopefully it will be clearer over time - perhaps not thanks to me, sorry
;-)

--
Patrice

<[email protected]> a écrit dans le message de (e-mail address removed)...
On Oct 16, 7:19 am, "Patrice" <http://www.chez.com/scribe/> wrote:
[cut]

Patrice, it has indeed been very nice of you to help me grasp the
topic of reference types. Thanks for the same. However I am extremely
sorry to confess that your answer has further compounded my
confusions.

I guess I need a break, think peacefully about it & come afresh
tomorrow with a fresh mind....so see you tomorrow......

Ron
 
Was afraid of that as I was not sure what caused the confusion.

The thing you'll see most often is :
- a variable stores something
- a value type is a type whose data are stored directly by this variable
- a reference type is a type whose data are stored as a reference (a
pointer) to the actual data

For example an integer will be directly stored in the variable (this is a
value type).
On the other hand an object (whose size can vary much, that have methods
etc...) is actually a reference (a pointer) on the actual data that allows
to implements such a behavior.

I wanted to mention that a variable name is basically itself an alias fora
storage location thinking that it could be what caused this confusion...

Hopefully it will be clearer over time - perhaps not thanks to me, sorry
;-)

--
Patrice

<[email protected]> a écrit dans le message de (e-mail address removed)...
On Oct 16, 7:19 am, "Patrice" <http://www.chez.com/scribe/> wrote:
[cut]

Patrice, it has indeed been very nice of you to help me grasp the
topic of reference types. Thanks for the same. However I am extremely
sorry to confess that your answer has further compounded my
confusions.

I guess I need a break, think peacefully about it & come afresh
tomorrow with a fresh mind....so see you tomorrow......

Ron
Hopefully it will be clearer over time - perhaps not thanks to me, sorry :-)

No...no....you still deserve a lot of thanks for trying so much to
help me understand this. It's my dumb brain which is at fault
actually.

Anyway, a new day..with a fresh mind..am starting to understand slowly
& steadily (after all, slow & steady wins the race!)....now for some
questions to ensure myself that I am starting to understand this...

Are all variables, be they value types or reference types, ALWAYS
stored in the stack? For e.g. consider the following code:

--------------------------------------
Class MyInt
Public MyValue As Integer
End Class

Sub Page_Load(..........)
Dim x As New MyInt
Dim y As New MyInt

x.MyValue = 15
y = x

y.MyValue = 30
Response.Write(x.MyValue)
End Sub
--------------------------------------

"MyInt", being a reference type, resides in the heap. "x" is also a
reference type but it is stored in the stack BUT it refers to the
class "MyInt" in the heap? So does that mean all variables,
irrespective of their types, are stored in the stack?

BTW, does "x" refer to the class "MyInt" or to the variable "MyValue"
in the class "MyInt"? For e.g. note the line

x.MyValue = 15

Does this mean the variable "MyValue" (which is in the heap) is
assigned a value of 15 & "x" just refers to the variable
"MyValue" (whose value is now 15 in the heap)?

Also note the line

y = x

The above line means that "x" & "y" point to the same object "MyInt"
but what about

y.MyValue = x.MyValue

Doesn't the above line mean that "x" & "y" point to the same object?

Thanks,

Ron
 
Back
Top