未能分配内存<NoMemoryError>

我想添加一个数组,我从Excel表格,这是一个二维数组[[row1contents],[row2contents],…]检索的值。 我想追加每一个这些行到一个CSV文件,我有代码适用于某些情况下,但在其他人,我得到“失败分配内存错误”。 它说它是一个以.join方法开始的问题

>

#the location of the csv that I want to append to csv_filepath = regression_folder + '/Regression.csv' #out_book is the name of the workbook where I get the data to append from @out_book.calculate # Grab output sheet with data from workbook # OUTPUT_DATA_SHEET is name of the sheet in the workbook, sheet is a method written to # retrieve a sheet output_sheet = @out_book.sheet(OUTPUT_DATA_SHEET) #puts "check if out_sheet empty" if @out_sheet.is_empty @out_sheet.createTable(output_sheet) end # read_range is method that reads in information from the sheet as 2D array listed above source = output_sheet.read_range(DEST_TABLE) # this is code to append 2D array to csv File.open(csv_filepath,'a'){ |f| f << source.map(&:to_csv).join; nil } puts "Total memory usage: #{ObjectSpace.memsize_of_all/1000.0} KB" 

但是,毕竟,我得到一个错误消息说>

  main.rb:217:in 'join': failed to allocate memory <NoMemoryError> from main.rb:217:in 'block in initialize' from main.rb:217:in 'open' from main.rb:217:in 'initialize' from main.rb:471:in 'new' from main.rb:471:in '<main>' 

第217行是File.open(csv_filepath,'a')…行,第471行是main被初始化的地方。

谁能帮助我?