. NET platform call Performance Optimization

Source: Internet
Author: User

. Before the emergence of NET, many mature libraries were stored in various applications in the form of C/C ++ or COM. These libraries or programs have been running for a long time, and very stable and mature .. NET provides a variety of methods to call unmanaged code in the managed code, but the calling performance will suffer a lot of losses. to optimize the performance of platform calling as much as possible, Here are several notes.

Minimize calls to unmanaged code. Therefore, avoid calling unmanaged code in the loop body as much as possible. Instead, try to write the entire loop body to unmanaged code, that is, a single platform call is used to complete as many tasks as possible;
The dll path specified by the DllImportAttribute can be placed in the program root directory as much as possible, because. NET searches for dll files under the root directory, searches under the windows System directory, and finally searches under all directories under the PATH environment variable. If not found, DllNotFoundException will be thrown;
If the name of the called function is specified, it is identified by ExactSpelling = True, because if this function is not found when MessageBox function is called ,. net will try to search for MessageBoxA or MessageBoxW, which is determined by CharSet in the DllImportAttribute attribute, if CharSet is set to CharSet. ansi searches for MessageBoxA, if it is CharSet. if Unicode is used, search for MessageBoxW;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.