Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在RAM密集型程序上过早退出ruby_Ruby_Exit - Fatal编程技术网

在RAM密集型程序上过早退出ruby

在RAM密集型程序上过早退出ruby,ruby,exit,Ruby,Exit,我正试图让我的Ruby文件打印出所有可能的IP地址 但是,它提前退出,没有错误 require 'ipaddress' #Is Installed RUBY_GC_HEAP_GROWTH_FACTOR = 0.1 #Changes How Much RAM Is Taken Every Request (Tested And Removed, Not The Problem) #Exits After Here ip = IPAddress "0.0.0.0/24" #First Ran

我正试图让我的Ruby文件打印出所有可能的IP地址

但是,它提前退出,没有错误

require 'ipaddress' #Is Installed

RUBY_GC_HEAP_GROWTH_FACTOR = 0.1 
#Changes How Much RAM Is Taken Every Request (Tested And Removed, Not The Problem)

#Exits After Here

ip = IPAddress "0.0.0.0/24" #First Range
ip.to('255.255.255.255') #End Range

#Exits Before This Point

out_file = File.new("out.txt", "w") #Create & OpenFile
out_file.puts("#{ip}") #Output Variable To File
out_file.close #Save And Exit
sleep(8)
RAM不是问题,因为它值8Gb,并且代码在达到我的RAM限制之前退出


是什么导致程序关闭?

我认为您的做法是正确的,但您应该以稍微不同的方式使用gem:

ip = IPAddress "0.0.0.0/0"

File.open("out.txt", "w") do |file|
  ip.each do |ip_address|
    file.puts ip_address
  end
end

sleep(8)

当我测试笔记本电脑时,它使用了有限且合理的内存。然而,我并没有将其写入文件,而是写入控制台。希望您准备好处理这将产生的文件大小。

问题是什么导致程序关闭?我有250Gb。希望这样就够了。我得到一个TB的驱动器。