bo*@coolgroups.com wrote:
Which is faster - a call to a system function or a call to a library
function?
and
This is what they asked me in an interview. what do you think they
were getting at?
Probably the expected answer had something to do with this:
If the program environment is a "normal" operating system, a library
function call is a straightforward call executed in the context of the
calling process. As a minimum, the internal overhead consists of
transferring the function parameters and saving the return address.
A system function call, on the other hand, may use some kind of trap
instruction, it may produce a switch to kernel/supervisor mode, may
require saving/restoring process information, etc., a much larger
overhead.
This refers to the time required to do the call/invocation only, with
no reference to the time required to execute the function.
That's why in many systems it is faster to read a file using, for
example, a 16K buffer, than reading it one byte at a time.
It reduces the number of read system calls and their overhead.