Официальный сайт главтрудсоцзащиты

Автор: postnami от 13.05.2017, 03:14, посмотрело: 774

The first difference between reference types and value types we will consider is that reference types are allocated on the heap and garbage-collected, whereas value types are allocated either on the stack or inline in containing types and deallocated when the stack unwinds or when their containing type gets deallocated. There are, however, some situations in which the characteristics of a value type make it more appropriate to use structs. In all other cases, you should define your types as classes.

Официальный сайт главтрудсоцзащиты

Value type instances are copied when they are passed by value. Good understanding of the differences in the behavior of reference types and value types is crucial in making this choice.

Официальный сайт главтрудсоцзащиты

Finally, reference types are passed by reference, whereas value types are passed by value. Therefore, allocations and deallocations of value type arrays are much cheaper than allocations and deallocations of reference type arrays. When an instance of a value type is changed, it of course does not affect any of its copies.

Официальный сайт главтрудсоцзащиты

Therefore, allocations and deallocations of value type arrays are much cheaper than allocations and deallocations of reference type arrays. The next difference is related to memory usage. It will not have to be boxed frequently.

Официальный сайт главтрудсоцзащиты

Therefore, value types should be immutable. Next, arrays of reference types are allocated out-of-line, meaning the array elements are just references to instances of the reference type residing on the heap. Reprinted by permission of Pearson Education, Inc.

Официальный сайт главтрудсоцзащиты

There are, however, some situations in which the characteristics of a value type make it more appropriate to use structs. In addition, in a majority of cases value type arrays exhibit much better locality of reference. The first difference between reference types and value types we will consider is that reference types are allocated on the heap and garbage-collected, whereas value types are allocated either on the stack or inline in containing types and deallocated when the stack unwinds or when their containing type gets deallocated.

Официальный сайт главтрудсоцзащиты

Finally, reference types are passed by reference, whereas value types are passed by value. They get unboxed when cast back to the value type. Therefore, value types should be immutable.

Официальный сайт главтрудсоцзащиты

Finally, reference types are passed by reference, whereas value types are passed by value. As a rule of thumb, the majority of types in a framework should be classes.

Официальный сайт главтрудсоцзащиты

Next, arrays of reference types are allocated out-of-line, meaning the array elements are just references to instances of the reference type residing on the heap. In all other cases, you should define your types as classes.

Официальный сайт главтрудсоцзащиты

The next difference is related to memory usage. Next, arrays of reference types are allocated out-of-line, meaning the array elements are just references to instances of the reference type residing on the heap.

Официальный сайт главтрудсоцзащиты

In addition, in a majority of cases value type arrays exhibit much better locality of reference. Value types get boxed when cast to a reference type or one of the interfaces they implement. In contrast, no such boxing occurs as reference types are cast.

Официальный сайт главтрудсоцзащиты

Finally, reference types are passed by reference, whereas value types are passed by value. It will not have to be boxed frequently. Changes to an instance of a reference type affect all references pointing to the instance.

Официальный сайт главтрудсоцзащиты

Therefore, assignments of large reference types are cheaper than assignments of large value types. Because boxes are objects that are allocated on the heap and are garbage-collected, too much boxing and unboxing can have a negative impact on the heap, the garbage collector, and ultimately the performance of the application. They get unboxed when cast back to the value type.


Because boxes are objects that are allocated on the heap and are garbage-collected, too much boxing and unboxing can have a negative impact on the heap, the garbage collector, and ultimately the performance of the application. Value type arrays are allocated inline, meaning that the array elements are the actual instances of the value type.


Категория: Техника

Уважаемый посетитель, Вы зашли на сайт как незарегистрированный пользователь.
Мы рекомендуем Вам зарегистрироваться либо войти на сайт под своим именем.
<
  • 0 комментариев
  • 0 публикаций
21 мая 2017 г. 3:31:24

ununin

  • Группа: Гости
  • Регистрация: --
  • Статус:
 
Это не совсем то, что мне нужно. Есть другие варианты?

<
  • 0 комментариев
  • 0 публикаций
27 мая 2017 г. 3:58:44

gehosli

  • Группа: Гости
  • Регистрация: --
  • Статус:
 
а вобщем смешно.

Информация
Посетители, находящиеся в группе Гости, не могут оставлять комментарии к данной публикации.
Оформление:

DataLife Engine - Softnews Media Group

Copyright © © Октябрь 2018 http://trend-systems.ru Media Group All Rights Reserved.
Powered by DataLife Engine © 2014