Packing and unpacking in. net

Source: Internet
Author: User

.. NET is divided into two types: Value Type and reference type, and a mechanism is designed in which all types are inherited from a root class: system. object, which is similar to all classes inherited from cobject in MFC.

A value-type instance is generally directly allocated to the stack and referenced by its address. When we want to allocate a reference type instance, we first create the Instance Storage Area in the heap, and then put a variable in the stack to store the address of the region. Our reference instance is actually the address value, not the bucket in the heap. At present, I have not understood the benefits of this design method.

As for packing, unpacking is to compare the basic type of value type with system. why do we need to design a conversion mechanism between object classes? I want to make a function that accepts object types, it not only accepts common class reference objects, but also accepts common value type objects. If we design all the basic types as reference types for this purpose, the execution effect will be more troublesome. After all, an int variable, instead of directly manipulating it, you need to use its address to perform operations around a bend, and it takes time and space. So we designed such a way.

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.