Hi
I posted this in the caching section, before noticing that it appears
to be a practically dead NG, so please excuse the x-post...
Can anyone advise on this please? Something is happening here and it's
driving me mad trying to work out what. For simplicity I've reduced all
code to a simple section running in my applications' Page_Load method:
(in declarations:
Private svcinfo As New serviceInfo
)
Private Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Cache.Item("ServiceInfo") Is Nothing Then
svcinfo = svcIMS.getServiceInfo
Cache.Insert("ServiceInfo", svcinfo)
Debug.WriteLine("Envelope in the cache is " &
Cache("ServiceInfo").env.ToString)
Else
' got one already thanks, so reload that.
svcinfo = Cache("ServiceInfo")
End If
cE = svcinfo.env
cE.minx = 10
cE.maxx = 20
cE.miny = 100
cE.maxy = 200
Debug.WriteLine("Changed local cE to be " & cE.ToString)
Debug.WriteLine("Envelope now in the cache is " &
Cache("ServiceInfo").env.ToString)
End Sub
And here's the output I get. The initial load in the cache is the value
I want to preserve, it should never be changed.
Envelope in the cache is SW: 166000,828000 : NE 232000,921000
Changed local cE to be SW: 10,100 : NE 20,200
Envelope now in the cache is SW: 10,100 : NE 20,200
The toString function for an Envelope is:
Overrides Function toString() As String
Return String.Format("SW: {0},{1} : NE {2},{3}", _minx, _miny,
_maxx, _maxy)
End Function
How come I have a local copy of what is in the cache (in cE) yet when I
change cE it affects what's in the cache? I don't get it... :(
Someone put me out of my misery please :)
Cheers
AW 3 1087
Hi AW,
svcinfo = Cache("ServiceInfo")
AFAIK, the "=" operator is an assignment operator, NOT a "copy" operator.
;-)
Here's the long explanation: An object is a reference type. What this means
is that an object is basically a pointer to a data structure. A variable is
a container for data. It is not the data itself, although it might look like
one due to programming syntax. So, when you assign the reference to an
object to a variable, you are saying that the variable now references that
object. A pointer is an address in memory. It "points to" the beginning of a
data structure. So, when you assign svcinfo to Cache("ServiceInfo") you are
assigning the same memory address to your variable; IOW, it now references
the same object.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
<an*****@gmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com... Hi
I posted this in the caching section, before noticing that it appears to be a practically dead NG, so please excuse the x-post...
Can anyone advise on this please? Something is happening here and it's driving me mad trying to work out what. For simplicity I've reduced all code to a simple section running in my applications' Page_Load method:
(in declarations: Private svcinfo As New serviceInfo )
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load If Cache.Item("ServiceInfo") Is Nothing Then svcinfo = svcIMS.getServiceInfo Cache.Insert("ServiceInfo", svcinfo) Debug.WriteLine("Envelope in the cache is " & Cache("ServiceInfo").env.ToString) Else ' got one already thanks, so reload that. svcinfo = Cache("ServiceInfo") End If
cE = svcinfo.env cE.minx = 10 cE.maxx = 20 cE.miny = 100 cE.maxy = 200
Debug.WriteLine("Changed local cE to be " & cE.ToString) Debug.WriteLine("Envelope now in the cache is " & Cache("ServiceInfo").env.ToString) End Sub
And here's the output I get. The initial load in the cache is the value I want to preserve, it should never be changed.
Envelope in the cache is SW: 166000,828000 : NE 232000,921000 Changed local cE to be SW: 10,100 : NE 20,200 Envelope now in the cache is SW: 10,100 : NE 20,200
The toString function for an Envelope is: Overrides Function toString() As String Return String.Format("SW: {0},{1} : NE {2},{3}", _minx, _miny, _maxx, _maxy) End Function
How come I have a local copy of what is in the cache (in cE) yet when I change cE it affects what's in the cache? I don't get it... :(
Someone put me out of my misery please :)
Cheers AW
Sorry, meant to reply to this yesterday.
That put me on the right track - my problem was indeed as you said. I
fixed it by extending my class to implement ICloneable so now I'm
cloning the object before assignment.
Thanks very much for your help Kevin, much appreciated. Taught me an
important concept that had given me the slip.
Ironic however in that in another part of the project, I had been
cloning another object so as to deal with this sort of problem. Having
done that, it would appear I slipped the blinkers straight back on
again... :(
Don't be too hard on yourself, Andrew. We all slip the blinkers on now and
again!
You're only in real trouble if Uncle Ernie drops his chopsticks!
--
;-),
Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
"AndrewW" <an*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com... Sorry, meant to reply to this yesterday.
That put me on the right track - my problem was indeed as you said. I fixed it by extending my class to implement ICloneable so now I'm cloning the object before assignment.
Thanks very much for your help Kevin, much appreciated. Taught me an important concept that had given me the slip.
Ironic however in that in another part of the project, I had been cloning another object so as to deal with this sort of problem. Having done that, it would appear I slipped the blinkers straight back on again... :( This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: dont bother |
last post by:
This is really driving me crazy.
I have a dictionary feature_vectors{}. I try to sort
its keys using
#apply sorting on feature_vectors
sorted_feature_vector=feature_vectors.keys()...
|
by: Keiron Waites |
last post by:
Please see the problem in action here: http://www.leadbullet.biz/contact.php
If you mouse over the fields, you will see that text is shown on the right.
The text makes the other fields move when...
|
by: apchar |
last post by:
I have a simple ad rotator that's driving mozilla and netscape a
little crazy. You know that symbol in the upper right corner of the
browser that animates while a page is downloading and is...
|
by: kfc1976 |
last post by:
Hi All,
First of all, following are the facts
1) I've been trying to solve the following issue for the past 8 hours
(Not Kidding)
2) If I can't find the answer, It will drive me completely crazy...
|
by: mat |
last post by:
Hi all,
This is weird and it is driving me nuts, please can someone explain how
I can get it to return the correct answer:
print '$_SESSION: '.$_SESSION.'<br />';
print '$_SESSION:...
|
by: kfc1976 |
last post by:
Hi All,
First of all, following are the facts
1) I've been trying to solve the following issue for the past 8 hours
(Not Kidding)
2) If I can't find the answer, It will drive me completely crazy...
|
by: rashpal.sidhu |
last post by:
Please help, this problem is driving me crazy !!
I am using metaphone to create phonetic keys. When i run the module
stand-a-lone it works fine.
I'm trying to create a runner for informix...
|
by: mark4asp |
last post by:
Every time the function below is called I get the alert. So I put a
deliberate error in there and I check the value of
(reportType=='MANDATE') in Firebug, which is found to be true. But
still the...
|
by: xtech1005 |
last post by:
Hello,
I'm trying to get a Select query in a stored proc to give the correct results but all I've done so far is pull hair out. Maybe one of you gurus out there can help me!
I have a table...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| | |