gpt4 book ai didi

arrays - 一个数组可以处理多少个元素 Node.js

转载 作者:太空宇宙 更新时间:2023-11-04 00:06:12 27 4
gpt4 key购买 nike

我正在尝试将对象放入基于大约 500.000 行或更多行的 txt 文件的数组中

我正在使用 require('readline') 来处理它,但是当达到第 470000 行(例如)没有错误、警告、通知时,处理会为自己“暂停”...

这是我的代码示例(原始代码填充 dataRow 对象,然后在到达第 411000 行时“暂停”):

let myList = [];
let lineReader = require('readline').createInterface({
input: require('fs').createReadStream(filePath).pipe(iconv.decodeStream('latin1'))
});
lineReader.on('line', function (line) {

// here there are a lot more fields, but I have to cut off for this example
let dataRow = JSON.parse('{"Agencia_Cobranca":"","Aliquota_ICMS":""}');

myList.push(dataRow);

//this if is only to follow what is happen
if( myList.length %10000 == 0 || myList.length>420000) {
console.log(" myList executed: ",myList.length, ' - ', JSON.stringify( myList[myList.length-1] ).length, ' - ' ,new Date() );
}

}).on('close',function(){
console.log('finished');
process.exit(0);
});

我正在使用这个命令行来执行

node --max-old-space-size=8192 teste

好吧...这就是结果,当实现这一行时屏幕就保持这种状态...永远不会结束并且没有错误:(

enter image description here

最佳答案

您的堆栈/RAM 可能已满并以奇怪的方式出错。我建议,如果可能的话,让你的程序更有内存效率,在阅读一行时做你需要做的一切,然后丢弃它。将其全部存储在内存中永远不是解决方案。

关于arrays - 一个数组可以处理多少个元素 Node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52185105/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com