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?
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.