C # Reference types and value types

Source: Internet
Author: User

1. Reference type

Most types in the FCL (Framework) are reference types, and reference types are always allocated in the managed heap, and C # 's new operator returns the memory address of the object, which is the memory address of the object's data. When using reference types, there are the following performance issues that we must be aware of in development:

A, memory must be allocated from the managed heap (that is, each new object consumes memory, and too many objects cause memory consumption)

b, each object allocated on the heap has some additional members that must be initialized

C, other bytes in the object (set for field), always set to 0

D. A garbage collection operation may be enforced every time an object is allocated from the managed heap

So when the reference type is in our application, the performance of the application is significantly reduced.

2. Value type

The reference types are described above, and the performance of the application is degraded when each object is allocated from the managed heap. Imagine that when you initialize a number 6 with the Int32 type or use float to initialize a floating-point 6.6, the memory is allocated once, and the performance of the application is severely affected. To provide application performance, the CLR provides a lightweight type named value type.

C # Reference types and value types

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.