+ 2
(Continuation to the previous answer)... These buffers are freed when we call the flush() or close() method. So with this infernal buffer, this memory is written to the buffer 100 times (writing to this buffer is very very efficient than writing to the main memory) and then finally written to the main memory when the close() method is called. So as a result, we reduced our 100 slow calls to the main memory writer thing, to a single call to the main memory writer(+100 calls to the buffer writer, but this is negligible compared to the main memory writer call).
12th Jan 2022, 3:18 PM
Rishi
Rishi - avatar
+ 2
I don't know much about Ruby, but I'll try to explain it in general. The "internal buffer" is a temporary storage space for storing the data which is intended to be written to main memory, that can be flushed later so that the number of write operations can be minimised and thus speeding up the option and reducing power consumption. Imagine you're creating a file in main memory and writing some numbers(say 1 to 100) in it. What you'll do will be something like the following snippet(meant to be a pseudo code) File myfile=open("numbers.txt"); for(int i=0;i<101;++i){ myfile.write(i); myfile.write('\n'); } myfile.close() Now, each time you call the write method, the writer is called and it writes an integer and a newline to the file and the writer is freed. In this seemingly small piece of code, it's been called 100 times, made to write 100 times, and freed 100 times. This produces a huge performance overhead. That's why these "infernal buffers" are created.
12th Jan 2022, 3:14 PM
Rishi
Rishi - avatar
+ 2
Ash I meant to say that it can store the data that we wanted to write to main memory, and flushed later
12th Jan 2022, 3:21 PM
Rishi
Rishi - avatar
+ 2
Ash oh looks interesting, I'll explore it when I get the time :D
12th Jan 2022, 3:22 PM
Rishi
Rishi - avatar
+ 2
Ash it's stored in a temporary memory, just like the input buffer
12th Jan 2022, 3:23 PM
Rishi
Rishi - avatar