I
I
IvanN7772017-01-28 18:19:22
ruby
IvanN777, 2017-01-28 18:19:22

Reading a very large stream from a file, in ruby?

The first thing that comes to mind, however, what happens if the line is one and two gigabytes.

$stdin.each_line do |line|
        
 end

Or is that better?
$stdin.each(' ') do |i|

end

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Mirilaczvili, 2017-01-28
@2ord

stackoverflow.com/questions/13849280/dealing-with-...

R
Rou1997, 2017-01-28
@Rou1997

however, what happens if the string is one and two gigabytes long.

First of all, there may not be enough RAM, I needed ten gigabytes for a decompiler written in Python, and the decompiled application would be very large, maybe I would need to buy a new computer, although if you think about why he needs to keep everything in RAM, it's just its poor quality.
Also, the risk of an exception increases with size, of course the file system is not a network to worry about different "breaks" like that, but sometimes it is important.
Everything else (performance or local problems of the OS or your Ruby) - see your OS and Ruby, respectively, if it uses buffer reading, then it seems that the OS should not limit the size, if there are problems with reading performance - try calling the OS API and compare msec, if it is strong different, you will have to somehow access the API directly, etc., in the end, it’s not so difficult to just create a 1-2 GB file and check.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question