简体   繁体   中英

Will C# Wrapper become slow than the original c++ library using dllImport?

I want to create a wrapper of realtime face analysis sdk located here http://face.ci2cv.net/ . I want to know that when I will create its wrapper using dllImport, will it effect the speed of the library ?

Probably not significantly, but it depends on how much library interacts with managed code.

The performance of unmanaged code should not be affected by the CLR. However, calls between the CLR and unmanaged code (P/Invoke calls (CLR-to-unmanaged) and reverse P/Invoke calls (unmanaged-to-CLR)) do have some overhead, particularly around argument and return value marshaling. Passing huge structures, arrays, or strings between the two often require blitting or more complex marshaling, and both take time to process.

So, if the library spends a lot of time churning in unmanaged land without interacting with any CLR code, performance should not be impacted. If you're having to make a lot of calls in and out over a short period of time, you will likely notice a decrease in performance compared with making those same library calls in a native binary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM