C# is also a pointer when storing class objects. If it is a non-generic type like ArrayList, or a generic type like List
There is no difference in Java because of type erasure. In C#, List<class type> does not have this boxing/unboxing thing.
If cat and dog can be derived from animal, it means that they are not structs. The class object contains a sync block and an RTTI (a specific type descriptor) in the memory layout, see here. The specific type can be determined based on this RTTI, which has nothing to do with boxing/unboxing. Class objects do not require boxing and unboxing.
The reason why value type must be boxed/unboxing is because its semantics are: a. As a whole, it is directly laid out to the current position. For example, a struct local variable is directly placed on the stack. If it is a field in a class, Directly into the memory occupied by this class object, instead of allocating a piece of memory from somewhere else and using a pointer to point to it (this is a class); and b. Therefore, every assignment must be copied, instead of using a pointer One finger is all it takes. Precisely because it lies directly, for a system without generics such as ArrayList, if structs of various sizes are allowed to lie in the ArrayList, then the element sizes will not be unequal, and arrayList[i] cannot pass offset + i * elemSize is calculated and can only be traversed element by element. This becomes a LinkedList with a time complexity of O(N) to find the Nth element, rather than an ArrayList of O(1). This is obviously not in line with your expectations, and it will be very difficult to implement the code. Very strange.
In fact, you don’t need to ask about this kind of thing. There are many ready-made answers on the Internet. Of course, you have to circumvent the firewall. Google it yourself: dotnet memory layout, or even better read ECMA Spec yourself, then use Windbg and then !loadby sos clr to see it yourself.
I have already posted so many links for you. If you continue to reach out, you will have to give up.
Are you referring to C++ or C#? These two are different. Lists in C++ do not directly store objects, but object pointers, because only object pointers and references are polymorphic
There is no difference in Java. When the compiler compiles, the type is uniformly erased to List, that is, the elements are treated as Object type, and are automatically converted to the specified type when getting.
Neither of the two people upstairs understand C#.
C# is also a pointer when storing class objects. If it is a non-generic type like ArrayList, or a generic type like List
There is no difference in Java because of type erasure. In C#, List<class type> does not have this boxing/unboxing thing.
If cat and dog can be derived from animal, it means that they are not structs. The class object contains a sync block and an RTTI (a specific type descriptor) in the memory layout, see here. The specific type can be determined based on this RTTI, which has nothing to do with boxing/unboxing. Class objects do not require boxing and unboxing.
The reason why value type must be boxed/unboxing is because its semantics are: a. As a whole, it is directly laid out to the current position. For example, a struct local variable is directly placed on the stack. If it is a field in a class, Directly into the memory occupied by this class object, instead of allocating a piece of memory from somewhere else and using a pointer to point to it (this is a class); and b. Therefore, every assignment must be copied, instead of using a pointer One finger is all it takes. Precisely because it lies directly, for a system without generics such as ArrayList, if structs of various sizes are allowed to lie in the ArrayList, then the element sizes will not be unequal, and arrayList[i] cannot pass offset + i * elemSize is calculated and can only be traversed element by element. This becomes a LinkedList with a time complexity of O(N) to find the Nth element, rather than an ArrayList of O(1). This is obviously not in line with your expectations, and it will be very difficult to implement the code. Very strange.
In fact, you don’t need to ask about this kind of thing. There are many ready-made answers on the Internet. Of course, you have to circumvent the firewall. Google it yourself: dotnet memory layout, or even better read ECMA Spec yourself, then use Windbg and then !loadby sos clr to see it yourself.
I have already posted so many links for you. If you continue to reach out, you will have to give up.
Are you referring to C++ or C#? These two are different. Lists in C++ do not directly store objects, but object pointers, because only object pointers and references are polymorphic
There is no difference in Java. When the compiler compiles, the type is uniformly erased to List, that is, the elements are treated as Object type, and are automatically converted to the specified type when getting.
There is no extra overhead when converting a subclass to a parent class