Daniel Mejia
02/01/2022, 4:40 PMvar out = "";
for( a in myArray ) {
out += out & a.toList() & chr(10) & chr(13);
}
fileWrite( csvFullPath, out );
This is pretty minimal code.Daniel Mejia
02/01/2022, 4:42 PMaliaspooryorik
deactivateduser
02/01/2022, 4:46 PM+=
will be very heavy. Try using stringbuilder, or user arrayToList on an array to not generate a ton of extra strings that need cleaned up.deactivateduser
02/01/2022, 4:46 PMDaniel Mejia
02/01/2022, 4:48 PMdomwatson
02/01/2022, 4:50 PMdeactivateduser
02/01/2022, 4:51 PMchr(10) & chr(13)
into a variable/spot in memory and appending that static string will also be more memory performant because it won't have to do 2 string generation/cleanups every time you append them both.Daniel Mejia
02/01/2022, 4:52 PMdomwatson
02/01/2022, 4:52 PMdomwatson
02/01/2022, 4:52 PMdomwatson
02/01/2022, 4:53 PMdeactivateduser
02/01/2022, 4:53 PMDaniel Mejia
02/01/2022, 5:00 PMthisOldDave
02/01/2022, 5:04 PMthisOldDave
02/01/2022, 5:06 PMdeactivateduser
02/01/2022, 5:20 PMdeactivateduser
02/01/2022, 5:21 PMdeactivateduser
02/01/2022, 5:24 PMdeactivateduser
02/01/2022, 5:26 PMDaniel Mejia
02/01/2022, 5:27 PMdeactivateduser
02/01/2022, 5:27 PMthisOldDave
02/01/2022, 5:28 PMshould
be faster but you would need to test it but otherwise no its the samedeactivateduser
02/01/2022, 5:29 PMDaniel Mejia
02/01/2022, 5:30 PMthisOldDave
02/01/2022, 5:34 PMDaniel Mejia
02/01/2022, 5:35 PMDaniel Mejia
02/01/2022, 5:35 PMdeactivateduser
02/01/2022, 5:35 PMDaniel Mejia
02/01/2022, 5:36 PMdeactivateduser
02/01/2022, 5:37 PMDaniel Mejia
02/01/2022, 5:38 PMdeactivateduser
02/01/2022, 5:38 PMDaniel Mejia
02/01/2022, 5:38 PMDaniel Mejia
02/01/2022, 5:39 PMdeactivateduser
02/01/2022, 5:39 PMaliaspooryorik
ageax
02/01/2022, 5:52 PMdeactivateduser
02/01/2022, 5:53 PMdeactivateduser
02/01/2022, 5:53 PMdeactivateduser
02/01/2022, 5:54 PMageax
02/01/2022, 6:07 PMageax
02/01/2022, 6:18 PMdeactivateduser
02/01/2022, 6:18 PMDaniel Mejia
02/04/2022, 5:28 AMcomponent {
function init(){ return this; }
void function arrayToString(array data){
var data = [
["asdf","132414","1324.12","1341kkk","ABC SAS ADEWK ADFADADA"],
["poui","0987","1824.12","poiu987","OIU SAS ADEWK ADFADADA"],
["wert","3546","1824.12","poiu987","OIU SAS ADEWK ADFADADA"]
];
var sb = createObject("java", "java.lang.StringBuilder").init();
var newline = chr(13) & chr(10);
for( a in data ) {
sb.append( a.toList() ).append( newline );
}
return sb;
}
}
Daniel Mejia
02/04/2022, 5:30 AMdomwatson
02/04/2022, 8:12 AMvar
on the a
variable @Daniel Mejia (code review eyes activated)domwatson
02/04/2022, 8:12 AMfor( var a in data ) {...
Daniel Mejia
02/04/2022, 3:14 PMdomwatson
02/04/2022, 3:14 PMarrayToString()
method at the same time, you can get trouble.domwatson
02/04/2022, 3:15 PMa
variable now is scoped to the entire instance of the CFC (by default). So its value is shared across all threads that are using the instance.Daniel Mejia
02/04/2022, 3:20 PMDaniel Mejia
02/05/2022, 12:34 AMfunction processFiles(required array filelist){
for( var f in filelist ){
var fArray = fileRead(f.path).listToArray(variables.newline);
var pcode = convertToPcodeArray( fArray ); // massages the data and adds other info
var fileString = arrayToString( pcode ); // Does this create a new scope on every loop?
fileWrite( outputPath, fileString );
}
}
function arrayToString(required array data){
var sb = createObject("java", "java.lang.StringBuilder").init();
var newline = chr(13) & chr(10);
for( a in data ) {
sb.append( a.toList() ).append( newline );
}
return sb;
}
domwatson
02/07/2022, 1:19 PMCREATE EMPTY OUTPUT FILE
DO
READ NEXT LINE from input file INTO srcLine
CONVERT srcLine to targetFormat
APPEND targetFormat to OUTPUT FILE
WHILE not end of input file
^^ then don't care about memory really at all.
CFML Functions:
var sourceFile = FileOpen( path, "read" );
try {
while( !FileIsEoF( sourceFile ) ) {
var ln = FileReadLine( sourceFile );
// convert ln to new format
// use FileAppend to output to new file
}
} catch( any e ) {
rethrow;
} finally {
FileClose( sourceFile );
}
Daniel Mejia
02/07/2022, 7:33 PMDaniel Mejia
02/07/2022, 7:34 PM