Basic Examples (3)
Two expressions that are identical are considered SameQ:
However, they are different instances of the same data:
By contrast, the value for c in the below is literally the same value for a, since both reference the same memory location:
Properties and Relations (5)
SameInstanceQ always returns True for a single argument:
Compare to SameQ:
SameInstanceQ[] is defined to be True:
This matches the behavior of SameQ:
Memory is typically allocated for each new expression that is created, even if it shares the same value as an existing expression:
In this case, a and b have identical values:
However, their values are stored separately in memory, since each expression was created separately:
Reusing expressions that are already created can save memory:
The value for a is literally the same value for b, since both reference the same memory location:
Many simple expressions are already preallocated in the kernel:
These are not necessarily atomic values:
Atomic expressions that are SameQ are not necessarily SameInstanceQ:
Possible Issues (2)
Having all of the corresponding parts of expressions be SameInstanceQ does not imply the parent expressions are SameInstanceQ:
Small integers are already created in memory, so they are always the same instance:
Larger integers are created as needed:
Find the range of small integers that are preallocated in memory: