[Vc.net] Handle __.net

Source: Internet
Author: User

C + + pointers have very powerful features. However, local pointers cannot be applied to managed objects because managed objects are stored in managed memory and are subject to garbage collectors. The main function of the garbage collector is two: one is to observe the object in memory, automatically reclaim the memory of the garbage object, and the second is to efficiently organize the memory to form a contiguous memory area.

The local pointer manually uses new to allocate memory and delete to free memory, and once the memory is sorted, the data for the object that the pointer refers to is corrupted. As a result, managed code requires a "trace pointer" that can be synchronized with the garbage collector, which is the handle. If the data that the handle points to is moved by the garbage collector, the handle is automatically updated. The handle is represented by the symbol "^" (pronounced "hat").

The handle uses operator gcnew to request dynamic memory, and no pointing handle is represented with a null value nullptr. Access the object that the handle refers to, using the "*" and "->" operators.

In a pointer operation in C + +, you can use the "&" operator to take the memory address of the operand. The handle provides a similar operator "%" for the managed type, returning the handle to the managed object. ' & ' cannot return an object handle in local memory. For example, an int variable is not a managed class object.


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.