C ++/CLI basic

Source: Internet
Author: User

1. Why need it?

Mainly it works as the bridge between managed code and native C ++ code, as it's the only graceful way to be able to talk to both sides.

Using/CLI compiler option, it can generate mixed code to benefit below cases:

1. I believe most companies have some old c ++ code. In the era of C ++, we have invested a lot in C ++ and may have produced many stable products. In today's surging. Net tide, do we need to rewrite this code? Of course, there is no need to know the legacy code. It does not mean that the code is faulty. On the contrary, most of such code is a mature product and has undergone many tests. If you rewrite the statement, you will introduce a lot of bugs and re-test the bug. It can be said that it is a thankless effort.

2. the emergence of DOTNET will not bring C ++ into the desperate situation. In some scenarios that require speed, such as Algorithm Implementation, pattern recognition, and drivers, C ++ is required. Any language is not perfect. Although we are all pursuing perfection, perfection does not exist. Therefore, we also need to make some trade-offs.

3. Sometimes we only need c ++ interfaces for third-party software. We do not have source code, so we do not have the possibility to rewrite the code. But we can write a wrapper through C ++/CLI for. net.

4. Sometimes some sensitive algorithms are implemented with unmanaged code for code security considerations. After all, managed code is easily decompiled.

 

2. Basic syntax

1. Ref/value

Ref/value class/struct: Reference Type + value type.

2. Boxing/unboxing

(Example)

Int I = 123;

Int ^ HI = I;

Int c = * Hi;

Hi = nullptr;

3. New keywords

Gcnew: allocate reference type object onto managed heap.

Type ^: declare a handle that just like CSHARP reference and C ++ native pointer.

Reference: http://msdn.microsoft.com/en-us/library/ms379617 (vs.80). aspx

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.