cfparam will be more expensive than cfset, just because it tests forthe
existence of a variable before setting it.
However it's like comparing apples to oranges. They are used for different
reasons.
If you have a page that may or may not have a variable passed to it, but you
have code on
the page that expects the variable, you dont want to overwrite a legitimate
value from your program with cfset.
In this case, cfparam would be the best choice.
There is also a difference between a variable initialized in the
application.cfm and a true application variable. You wouldn't want to
cfparam a true application variable, since it;s in memory, and you could run
into a situation where multiple people are setting it at the same time.
Initializing variables in the application.cfm is very easy, but if you are
really worried about performace. Putting all of your
constant varaibles in a structure then scoping the structure in the
application scope, will be faster than reinitializing the variable on every
page, at the cost of a little bit of memory.
If you only have a handful of variables that you actually need throughout
the application, the performace his to just cfset them on every page is
minimal, and probably not worth the time it will take to code them better
though. You also have to think about locking with the in memory scopes, like
the application scope.
Lets say you have 30 variables and a high traffic site though, it may then
pay off to optimize, rather than let Moore take care of it ;-)
Here is an example...
In your application.cfm test for the existence of the structure, because
application variables time out.
<cflock type="EXCLUSIVE" timeout="5">
<cfif NOT isDefined("application.globalVars")>
<cfset globalVars = structNew()>
Then you set all yourvariables here...
<cfset globalVars.dsn = "myDSN">
<cfset globalVars.password = "password">
...
Then application scope the structure.
<cfset application.globalVars = "">
<cfset application.globalVars = globalVars>
</cfif>
</cflock>
You can then reference the individual variables throughout your application
with #application.globalVars.dsn#.
This can be made even faster with the use of cfscript too.
jon
----- Original Message -----
From: "Bill Davies" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Wednesday, April 11, 2001 5:17 PM
Subject: RE: IsDefined('') v. <cfset>
> So would <cfparam> be cheaper than just doing a <cfset> anyway - say for
an
> Application variable whose value is constant?
>
> -----Original Message-----
> From: Will Swain [mailto:[EMAIL PROTECTED]]
> Sent: 11 April 2001 17:27
> To: CF-Talk
> Subject: RE: IsDefined('') v. <cfset>
>
>
> Yup, CFPARAMs in your application.cfm file will 'set' empty variables,
which
> you can fill later.
>
> That way, you don't need to check for their existence, just see what they
> are.
>
> Cheers
>
> Will
>
> -----Original Message-----
> From: Bob Silverberg [mailto:[EMAIL PROTECTED]]
> Sent: 11 April 2001 15:29
> To: CF-Talk
> Subject: RE: IsDefined('') v. <cfset>
>
>
> This doesn't answer your question directly, but if you are really going to
> test for the existence of a variable, and create it if it doesn't exist,
I'd
> suggest using <cfparam> which will accomplish both of those things in one
> step. I only used IsDefined if I want to check for the existence of a
> variable, and I'm NOT going to create it if it doesn't exist.
>
> Bob
>
> -----Original Message-----
> From: Bill Davies [mailto:[EMAIL PROTECTED]]
> Sent: April 11, 2001 10:12 AM
> To: CF-Talk
> Subject: IsDefined('') v. <cfset>
>
>
> Anyone have any idea whether an IsDefined('') 'costs' more than a <cfset>?
>
> i.e. Which is more work for the server - to test for the existence of a
> variable (and create it if it doesn't exist) or create or overwrite it
> anyhow?
>
> Thanks.
>
>
> Bill Davies
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists