Barney,
Thank you so much for your reply. I need to digest this one.
Have a great weekend!
Regards,
JB
Barney Boisvert wrote:
>When I'm building files, I usually use build up a string/array (depending on
>the situation) in memory, and then flush it to the file periodically,
>because string concatenation gets expensive as the string gets large. This
>example (a horribly contrived one) uses the string concatenation method, and
>has code to use the array append method commented out for illustrative
>purposes. I didn't test, so it may not be perfect, but it should be close.
>
><cfset filename = expandPath('./data_file.txt') /> <!--- data file --->
><cfset s = "" /> <!--- temp variable --->
><!---
><cfset a = arrayNew(1) />
>--->
><cfset flush_frequency = 50 /> <!--- how often to flush to file --->
><cfloop query="get">
> <cfset s = s & "name: #name#, dob: #dateOfBirth#" />
> <!---
> <cfset arrayAppend(a, "name: #name#, dob: #dateOfBirth#") />
> --->
> <cfif month(dateOfBirth) EQ month(now()) and day(dateOfBirth) EQ
>day(now())>
> <cfset s = s & " happy birthday!" />
> <!---
> <cfset a[arrayLen(a)] = a[arrayLen(a)] & " happy birthday" />
> --->
> </cfif>
> <cfif currentrow MOD flush_frequency EQ 0>
> <cffile action="append"
> file="#filename#"
> output="#s#" />
> <cfset s = "" />
> <!---
> <cffile action="append"
> file="#filename#"
> output="#arrayToList(a, chr(10))##chr(10)#" />
> <cfset a = arrayNew(1) />
> --->
> </cfif>
></cfloop>
><cffile action="append"
> file="#filename#"
> output="#s#" />
><!---
><cffile action="append"
> file="#filename#"
> output="#arrayToList(a, chr(10))#" />
>--->
>
>I haven't done any formal performance testing, but it's not noticably
>differe for small data sets, and noticably faster for large data sets. Just
>don't forget that <cfset s = "" /> after the flush, or you'll kick your
>server's ass, trust me. ; )
>
>HTH,
>barneyb
>
>
>---
>Barney Boisvert, Senior Development Engineer
>AudienceCentral
>[EMAIL PROTECTED]
>voice : 360.756.8080 x12
>fax : 360.647.5351
>
>www.audiencecentral.com
>
>
>
>
>>-----Original Message-----
>>From: James Blaha [mailto:[EMAIL PROTECTED]
>>Sent: Tuesday, July 01, 2003 10:05 AM
>>To: CF-Talk
>>Subject: best practice for building a large text file?
>>
>>
>>All:
>>
>>What's the best practice for building a large text file? Is it better to
>>use CFFILE and APPLEND or use an array then once you have the
>>information use arraytolist and then use CFFILE to create the text file?
>>
>>I have a 30 meg text file that I'm building line by line.
>>
>>Regards,
>>James Blaha
>>
>>
>>
>>
>>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
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
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4