My recommendation would be to initialize the CFC with the string as an
initial argument, then call the different iterative methods without sending
the string over and over: just modify the variable within the CFC after
the init.
Ex:
<cfcomponent displayName="stringModder">
<cfset variables.myString = "" />
<cffunction name="init" access="public">
<cfargument name="myLongString" type="string" required="true" />
<cfset variables.myString = arguments.myLongString />
</cffunction>
<cffunction name="replaceSmartQuotes" access="public">
<cfset variables.myString = replaceList(variables.myString,
chr(145) &
"," chr(146), "','") />
</cffunction>
<cffunction name="replaceLineBreaks" access="public">
<cfset variables.myString = replace(variables.myString, chr(13)
&
chr(10), "<br />", "all") />
</cffunction>
</cfcomponent>
Then in the calling template:
<cfset stringObj = createObject("component",
"StringModder").init(form.bigTextValue) />
<cfset newString = stringObj.replaceSmartQuotes() />
<cfset newString = stringObj.replaceLineBreaks() />
etc ...
----------------------------------------
From: "Brook Davies" <[email protected]>
Sent: Friday, March 04, 2011 12:41 PM
To: "cf-talk" <[email protected]>
Subject: CFC arguments, passing large strings
Hello,
I have a CFC which does some string parsing to find and replace wildcards.
Within the CFC I am calling a method over and over and passing in the
entire
string as an argument. The method does some magic and returns a result.
The string could be a large (like a 2 page document) string and since its
being provided as an argument and is not inside an object/struct, I
believe
its passed by value. Which means, unless I am mistaken, if I call the
internal method 100 times, and pass in this large string am I creating a
ton
of overhead/memory usage?
Would I be better off creating a temp structure to hold the string and
other
arguments (which change with each iteration) and passing that into my
method
so its passed by reference instead?
What do you think?
Brook D.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:342760
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm