Heap, stack, and value type, reference type

xiaoxiao2021-03-06  93

The stack is characterized by fast and efficient, disadvantages is limited, data is not flexible; and the stack is flexible, and the data adaptation surface is wide, but the efficiency has a decrease. The memory allocation of the stack is automatically released, and there is no release function. The allocation of the spatial space is always dynamic. Although all data spaces are released back to the system at the end of the program, the exact application memory / release memory is a basic element of a good program, and there will be GC in .NET to process memory. freed.

In addition to the interface is an exception, the type in the general type system is divided into two categories: value type and reference type. There will be some performance problems when using the reference type, so if a system is fully used by reference types, the performance of this system will be greatly weakened; therefore .NET Framework designer retains the Struct data type, and there is no in the Java language. Struct data type.

Value type:

Including primitive types, user-defined structures or enumeration types

Inherit from System.ValeType type

Assign on the stack

Copying

By default, the parameters are passed, unless REF keywords.

Quote type:

C # predefined reference types include Object and String types, user-defined reference types can be interface type, class type, and commission type

Inherited from System. Object Type

Use "New" keyword on the hosted stack

Assignment

There may be several references to the same object, so the operations for one variable will affect the same object being used for another variable.

Transfer variables with reference

转载请注明原文地址:https://www.9cbs.com/read-123872.html

New Post(0)