Yes, that would work.  I suppose it breaks encapsulation, since the "scope" 
of the struct is 'known' to the CFC, but it should accomplish what you're 
after.  If you do that, you technically wouldn't even need return values 
from the CFC, since changes to made to the method argument, would be made 
to the actual struct variable in the calling template.


----------------------------------------

From: "Brook Davies" <cft...@logiforms.com>
Sent: Friday, March 04, 2011 2:35 PM
To: "cf-talk" <cf-talk@houseoffusion.com>
Subject: RE: CFC arguments, passing large strings

But if I wrap it in structure, then it would be passed by reference.
Wouldn't this alleviate the memory usage issue?

Brook

-----Original Message-----
From: Jason Fisher [mailto:ja...@wanax.com] 
Sent: March-04-11 10:24 AM
To: cf-talk
Subject: RE: CFC arguments, passing large strings

Oh, well, if it's a singleton, then you're going to end up taking up those
whacking great chunks of server memory on every request cycle.  I would
strongly consider moving it out of application scope for that very reason,
but I certainly don't know the entire app structure so that's just a shot 
in
the dark.

----------------------------------------

From: "Brook Davies" <cft...@logiforms.com>
Sent: Friday, March 04, 2011 1:18 PM
To: "cf-talk" <cf-talk@houseoffusion.com>
Subject: RE: CFC arguments, passing large strings

I should have mentioned the CFC is stored in the application scope, so I
can't do that...

Brook

-----Original Message-----
From: Jason Fisher [mailto:ja...@wanax.com]
Sent: March-04-11 9:56 AM
To: cf-talk
Subject: re: CFC arguments, passing large strings

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" <cft...@logiforms.com>
Sent: Friday, March 04, 2011 12:41 PM
To: "cf-talk" <cf-talk@houseoffusion.com>
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:342768
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to