Status/Resolution/Reason: Closed/Won't Fix/
Reporter/Name(from Bugbase): Travis Walters / Travis Walters (Travis Walters)
Created: 03/09/2016
Components: Language
Versions: 2016
Failure Type: Enhancement Request
Found In Build/Fixed In Build: Alpha_v12 /
Priority/Frequency: Trivial / Some users will encounter
Locale/System: English / Win All
Vote Count: 0
Greetings,
I was thinking about my early programming days back when I used C/C++/Java a lot and how I could pass variables by reference and use pointers. It sort of got me curious as to whether it was or could be possible with ColdFusion.
I found a [url=http://www.bennadel.com/blog/275-passing-arrays-by-reference-in-coldfusion-sweeet.htm]Blog Post by Ben Nadel[/url] that was posted some time ago back in 2006 by the looks of it. I think those were the ColdFusion MX days =)
I put together a bit of code on his page below:
[Quote]<!--- Function AddGirls To Include Additional Girl Names --->
<cffunction name="AddGirls" returntype="void" output="false" hint="Adds some girls to the passed in array.">
<!--- Define arguments. --->
<cfargument name="Array" type="array" required="true" />
<!--- Add some girls to the array. --->
<cfset ArrayAppend( ARGUMENTS.Array, "Heather" ) />
<cfset ArrayAppend( ARGUMENTS.Array, "Azure" ) />
<cfset ArrayAppend( ARGUMENTS.Array, "Myriam" ) />
<cfset ArrayAppend( ARGUMENTS.Array, "Lori" ) />
<!--- Return out. --->
<cfreturn />
</cffunction>
<!--- Define the array. --->
<cfset ArrGirlNamesByValue = ArrayNew( 1 ) />
<!--- Set some values. --->
<cfset ArrGirlNamesByValue[1] = "Sarah" />
<cfset ArrGirlNamesByValue[2] = "Libby" />
<cfset ArrGirlNamesByValue[3] = "Mary-Kate" />
<cfset ArrGirlNamesByValue[4] = "Ashley" />
<!--- Dump Initial ArrGirlNamesByValue Values --->
<cfdump var="#ArrGirlNamesByValue#">
<!--- ArrGirlNamesByValue Names Variable Passed By Value --->
<cfset AddGirls( ArrGirlNamesByValue ) />
<!--- ArrGirlNamesByValue Values Remain Unchanged Due to Passing By Value --->
<cfdump var="#ArrGirlNamesByValue#">
<!--- Define the array AS AN ARRAY LIST --->
<cfset ArrGirlNamesByRef = CreateObject("java","java.util.ArrayList").Init() />
<!--- Set some values. --->
<cfset ArrGirlNamesByRef[ 1 ] = "Sarah" />
<cfset ArrGirlNamesByRef[ 2 ] = "Libby" />
<cfset ArrGirlNamesByRef[ 3 ] = "Mary-Kate" />
<cfset ArrGirlNamesByRef[ 4 ] = "Ashley" />
<!--- Dump Initial ArrGirlNamesByRef Values --->
<cfdump var="#ArrGirlNamesByRef#">
<!--- ArrGirlNamesByRef Values Changed Due to Passing By Reference --->
<cfset AddGirls( ArrGirlNamesByRef ) />
<!--- ArrGirlNamesByRef Changed With Existing ArrayAppend Function --->
<cfset ArrayAppend( ArrGirlNamesByRef, "Kimmie" ) />
<!--- ArrGirlNamesByRef Changed With Existing ArrayPrepend Function --->
<cfset ArrayPrepend( ArrGirlNamesByRef, "Christina" ) />
<!--- ArrGirlNamesByRef Changed With Existing ArrayDeleteAt Function --->
<cfset ArrayDeleteAt( ArrGirlNamesByRef, 4 ) />
<!--- ArrGirlNamesByRef Changed With Existing ArrayInsertAt Function --->
<cfset ArrayInsertAt( ArrGirlNamesByRef, 4, "Jo" ) />
<!--- Display Final Changed ArrGirlNamesByRef CFDump --->
<cfdump var="#ArrGirlNamesByRef#">
[/Quote]
My first thought is that it would be nice if the ColdFusion function ArrayNew would have a second parameter allowing it to be able to be passed by reference instead of by value.
Using java.util.ArrayList and passing by reference was a huge performance difference at least in 2006 and I believe it still would be today. Passing by reference means that an additional copy of data does not have to be placed into memory. This would decrease overhead and allow more overall processes to run at the same time.
[Quote Ben Nedal]Holy crap! The test was insane! For 10,000 iterations, the ColdFusion array test took a draw-dropping 292,087 ms. The java.util.ArrayList test took a sleek, sexy 281 ms. Grabbing the calculator, I see that this means that the java.util.ArrayList performs in .00096 percent of the time that the ColdFusion array took. I don't think I have ever seen such a HUGE performance difference in all my testing in ColdFusion.[/Quote]
Another thought is this - I wonder what else could be passed as reference compared to passing by value? What other functions could have a huge performance boost?
How about introducing the * and & operators in ColdFusion?
[Quote]
<!--- Normal Variable --->
<cfset x = 1 />
<!--- Pointer Variables (Not sure if you would allow a space between the * and the var name) --->
<cfset *p1 = 2 />
<cfset * p2 = 3 />
<!--- Assign Memory Address of x to p1 --->
<cfset p1 = &x />
[/Quote]
Thoughts? Comments? Suggestions for Improvement?
Sincerely,
Travis Walters
----------------------------- Additional Watson Details -----------------------------
Watson Bug ID: 4126690
External Customer Info:
External Company:
External Customer Name: Travis Walters
External Customer Email: TWALTERS84@HOTMAIL.COM
External Test Config:
Attachments:
Comments: