Question

What is the overhead of calling the operating system some large amount of times?

For instance, Microsoft has an API called "Getpixel" You have to supply the x,y co-ordinates and it will return a colour value. Setpixel then has to make millions of requests to the OS.

What exactly is the overhead of doing this?

Was it helpful?

Solution

Well for the example you give of GetPixel, it is slow because it uses a kernel mode driver to do the actual work, and in that driver it does a number of validation and locks to see if the device context you passed is actually a DC and to make sure it isn't changed somewhere in the function, then it makes a copy of an area into a new bitmap in memory and reads the pixel you want from that and after that deallocates the bitmap.

So you have a kernel mode switch, locks, validations and memory allocation, copying, and freeing and then another mode switch back to user land, all of which take time, finding a way to do GetPixel functionality in your program will save you tens of thousands of clock cycles.

But another API call may well cost no more than a few memory reads and writes, so it depends very much on which call into the OS you make.

OTHER TIPS

No universal answer. Depends on the call -e.g. calls involving I/O will be slower than those that don't-, depends on how the system calls are implemented by the OS -e.g. interrupts? jumps?- and depends on the architecture -e.g. does the architecture implements a system call instruction? does it do it by normal jumps?-.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top