Skip to content

Memory Allocation and Performance

IT Notes → C# @ December 22, 2020

  • Separate allocations of memory for the reference and object.
  • The object consumes as many bytes as its fields, plus additional administrative overhead (typically 12 bytes).
  • Each reference to an object requires an extra 4 or 8 bytes, depending on whether the .NET runtime is running on a 32- or 64-bit platform.
  • The float and double are called floating-point types and are typically used for scientific calculations.
  • The decimal type is typically used for financial calculations, where base-10-accurate arithmetic and high precision are required.
  • For reference types, equality, by default, is based on reference (Exception: String), as opposed to the actual value of the underlying object as in case of value types.
  • All array indexing is bounds-checked by the runtime.
  • Stack for local variables and parameters. An example is a reference to an object which is local.
  • Heap for objects.
  • If the instance was declared as a field within an object, or as an array element, that instance lives on the heap.
  • An object is eligible for deallocation as soon as nothing references it
  • The heap is also used to store static fields and constants and will live on until the application domain is torn down.
  • An unreferenced object is eventually collected by the garbage collector. It can’t be explicitly be removed.
  • Whenever an unboxing or downcast occurs, the runtime checks the type dynamically.
  • Generic collections are better than collections if and only if it stores value type and has large entries. For reference type they are same. Generally former is better. Example List<T> is better than Array List for value entries > 500.
  • Presently, .NET does not provide a mechanism for constraining a generic type parameter to be serializable.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x