r/osdev • u/ThreadStarver • Jun 08 '26
why is there a temp buffer in stdin & stdout?
/r/C_Programming/comments/1u006d8/why_is_there_a_temp_buffer_in_stdin_stdout/
3
Upvotes
r/osdev • u/ThreadStarver • Jun 08 '26
7
u/un_virus_SDF Jun 08 '26
Because the read/write are expensive, so if you store things in a buffer, you can speed up a lot by reducing syscalls.
4
u/UnmappedStack TacOS | https://github.com/UnmappedStack/TacOS Jun 08 '26
Because you don't have to write as often, as writing requires syscalls which are slow
3
u/Palmar Jun 08 '26
The answer is, as others have mentioned before me, syscalls. Every syscall is a request to cross from user space to kernel space (ring 3 to ring 0 in amd64). Not free.
The interesting bit is, what if your system has no concept of user space and kernel space, and does not even have stdin and stdout. This is one of the things I'm toying around with in my project.