> Obviously, your function names must be unique per CFM, so the
> unique name for all functions is a concatenation of the CFM
> name and the function name.

Indeed that is true, the problem comes when I'm trying to work out which CFM page 
contains the function: I'm performing the key generation from within the CFC, so it's 
a bit of a hassle to work out where the function "came from".  Any way, the toString() 
method I provided initially basically does what you have stated, in a round about kind 
of way.

> Here is a quick UDF (read not tested) that does what you need.
> ...
>               return theName.hashCode();

That's not going to identify a function uniquely - the hashCode() method will return 
the hashcode for the theName variable, not for the function.  If I called the method 
again with exactly the same value, it'd return a different hashcode.

Saying that however, using hashCode() against the function directly _will_ work and 
also saves on the hash() call.  I can replace the key generation line:

<cfset key = this.KEYPREFIX & hash(myFuncRef.toString())>

with the following, removing one method call per generation (not much, but I'm sure 
they'll all add up, especially as it's a crypto function call I'm removing) and 
guaranteeing the key is unique (and always the same) for that function:

<cfset key = this.KEYPREFIX & myFuncRef.hashCode())>

For those that are wondering, the hashCode() method is a java method implemented in 
the base Object class that all other classes extend from by default.  By definition it 
is guaranteed to return a unique (integer) ID for each object and if the function is 
called on the same object more than once during the lifetime of the Java application 
(i.e. CFMX), the same hash code will be returned on each call.  Generally, the unique 
ID is generated from the internal memory address of the given object.

Additionally, the key generated by the hashCode() method is much shorter than using a 
hash(toString()) representation (8 or so bytes compared to 32) so storing the key in 
memory won't eat up so much RAM.  Not exactly the biggest gain in the world but 
sometimes every byte counts...  ;)

Cheers for the pointer Matt, even if it wasn't exactly what you meant...  ;)

> You might also be interested in the following Java class

That's cool, but surely the toString() method I stated returns (basically) this info 
anyway, but it is more relevant for the use I need because it also includes the 
sub-class for the function reference.  Ta anyway - may well come in useful at some 
point!

The question still remains, is this a sensible way to go?  No one's come down on me 
like a ton of bricks so I'm guessing it's OK...

Tim.

------------------------------------------------------- 
RAWNET LTD - Internet, New Media and ebusiness Gurus. 
Visit our new website at http://www.rawnet.com for 
more information about our company, or call us free 
anytime on 0800 294 24 24. 
------------------------------------------------------- 
Tim Blair 
Web Application Engineer, Rawnet Limited 
Direct Phone : +44 (0) 1344 393 441 
Switchboard : +44 (0) 1344 393 040 
------------------------------------------------------- 
This message may contain information which is legally 
privileged and/or confidential. If you are not the 
intended recipient, you are hereby notified that any 
unauthorised disclosure, copying, distribution or use 
of this information is strictly prohibited. Such 
notification notwithstanding, any comments, opinions, 
information or conclusions expressed in this message 
are those of the originator, not of rawnet limited, 
unless otherwise explicitly and independently indicated 
by an authorised representative of rawnet limited. 
------------------------------------------------------- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/lists.cfm?link=t:4
Subscription: http://www.houseoffusion.com/lists.cfm?link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Signup for the Fusion Authority news alert and keep up with the latest news in 
ColdFusion and related topics. 
http://www.fusionauthority.com/signup.cfm

Reply via email to