> I have the following code which seems to work for reading application &
> session variables <snip>
> Is this method (aliasing variables at the start of the file) okay to
> use, or will I need to re-code everything to avoid problems. It seems
> to work so far...
<snip>

That should work just fine for string data because (to the best of my
knowledge) CF passes simple data types by value.  This means that (using
your code as an example) SessionUserID is a brand new variable with the same
value as Session.UserID.

Just be careful if you have complex data types like structures, queries, etc
stored in the session or application scope.  CF passes complex data types by
reference, which works like so:

<CFLOCK SCOPE="Session" TIMEOUT="5" TYPE="ReadOnly">
 <CFSET SessionMyQuery = Session.MyQuery>
</CFLOCK>

SessionMyQuery is basically created as a pointer to Session.MyQuery, which
means that you still need to lock reads and writes to it.  So if you were to
reference SessionMyQuery later in your page without locking it you would run
the risk of corrupting your session data.

To get around this you can use the CF 4.5 function Duplicate() (maybe
DeepCopy(), I can't remember... I don't use 4.5). Also note that the
StructCopy() will only copy the TOP level of a structure: if you have nested
structures, they will be passed by reference.  If you want an exact
duplicate of a complex, nested structure then use Duplicate().

So the moral of the story is:
1) You can create "local" copies of simple data types within a lock, and
then access the local copies outside of a lock later in the page
2) If you want to create local copies of complex data types then use
Duplicate().  However, first decide which will impose the greater
performance hit: Duplicating a large complex object or sprinkling a few
locks through your code.

Hope this helps,
Seth Petry-Johnson
Argo Enterprise and Associates

------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to