Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

windows API: how expensive is it to call an API function?

Tags:

winapi

Do calling an API function considered an expensive operation? (when comparing it to a function call which is part of my application)
I understand that some API functions cause a leap to kernel mode but is it true for all of them?

More specific: how expensive will it be to call GetThreadId function?

like image 423
Eli Avatar asked Mar 27 '26 22:03

Eli


1 Answers

GetThreadId of an arbitrary thread requires a kernel switch, so it more expensive than GetCurrentThreadId which retrieves cached data from user mode.

The cost of an API is highly dependent on the nature of the API itself. An API that retrieves a cached value from user mode is very cheap, an API that transitions to kernel mode is much more expensive, on the order of microseconds. API's that read or write to disk can cost dozens of milliseconds. API's that work on the network can take seconds or minutes.

like image 50
Michael Avatar answered Mar 31 '26 05:03

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!