无法分配内存<nomemoryerror>

时间:2016-11-18 01:14:34

标签: ruby excel file csv out-of-memory

我正在尝试添加一个从Excel工作表中检索的值数组,这是一个2D数组[[row1contents],[row2contents],...]。我想将这些行中的每一行附加到CSV文件中,并且我的代码适用于某些情况,但在其他情况下,我得到了&#34;无法分配内存错误&#34;。它说它是一个以.join方法

开头的问题

&GT;

  #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"

然而,在所有这些之后,我收到一条错误消息 &GT;

  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,&#39; a&#39;)...行,第471行就是主要初始化的地方。

任何人都可以帮助我吗?

0 个答案:

没有答案