0

EDIT: Looking at the Remarks on this MSDN page

https://msdn.microsoft.com/en-us/library/system.string.intern(v=vs.110).aspx

for String.Intern it mentions how the CLR interacts with literal strings and an intern pool.

I was wondering if there are any other examples of adding references to an intern pool other than for string literals?

Can I find an explicit list of what all is interned?

Ethan
  • 144
  • 11
  • I'm unsure of how to demonstrate my research effort for this question. I have search Google, Stack Overflow and MSDN in an effort to find other references to an intern pool and have not been successful(hence the question) I obviously feel this question is useful, and I don't see what needs to be clarified? – Ethan May 20 '15 at 14:00

1 Answers1

1

In order to be eligable for interning, a type must be:

1) A reference type. Interning uses the reference of an object, to place have it point to a general location instead of the area in the heap that is allocated to the object. Since value types are just addressed by value, there would be no way to intern them.

2) Immutable. A type that is interned can be referenced by multiple objects that were meant to be independent and the user may not even know that they are interned. Therefore, the value of the object cannot change.

Below is a list of the basic CLR types and their corresponding C# alias. All of the types, except System.String are value types. All of them, except System.String are therefore also mutable. Because of this, only System.String would be a candidate for interning (and yes, it is the only class that is interned).

  • System.Boolean bool
  • System.SByte sbyte
  • System.Int16 short
  • System.Int32 int
  • System.Int64 long
  • System.Byte byte System.UInt16 ushort
  • System.UInt32 uint
  • System.UInt64 ulong System.Single float
  • System.Double double
  • System.Char char System.String string
  • System.DateTime N/A
  • System.Decimal decimal
Mattias
  • 1,110
  • 1
  • 11
  • 26