For a very large file, something in between.  If you build a big file within
memory (in an array or text variable) then you risk bringing the machine to a
standstill or even crashing it.

If you append to a file line by line a couple of million times you'll also tax
the system and won't be doing yourself any favors, since the program will
probably take much longer to execute than if you built the file in memory first
and merely dumped it to disk at the end.

I'd figure out the average line length and pick some number of lines to dump to
the file each time based on the specs of the machine.

There's no real need to use arrays and lists.  Just use a simple variable and
terminate each line with a CR/LF pair.

<cfset outputfile = "C:\myfile.txt">
<cfset linesperwrite = 1000>
<cfset crlf = Chr(13) & Chr(10)>
<cffile action="write" file="#outputfile#" output="" addnewline="no">
<cfset x = "">
<cfset linecount = 0>
<cfloop (until you're done)>
  <cfset some_stuff = ...>
  <cfset x = x & "#some_stuff#" & crlf>
  <cfset linecount = linecount + 1>
  <cfif linecount gte linesperwrite>
    <cffile action="append" file="#outputfile#" output="#x#" addnewline="no">
    <cfset x = "">
    <cfset linecount = 0>
  </cfif>
</cfloop>
<!--- Don't forget to dump any remaining lines to the file --->
<cffile action="append" file="#outputfile#" output="#x#" addnewline="no">


----- Original Message ----- 
From: "James Blaha" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Tuesday, July 01, 2003 11:04 AM
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.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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

This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.
http://www.cfhosting.com

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to