Interning (computer science)
Data structure for reusing strings / From Wikipedia, the free encyclopedia
This article is about the computer science usage. For professional training programs, see Internship.
In computer science, interning is re-using objects of equal value on-demand instead of creating new objects. This creational pattern[1] is frequently used for numbers and strings in different programming languages. In many object-oriented languages such as Python, even primitive types such as integer numbers are objects. To avoid the overhead of constructing a large number of integer objects, these objects get reused through interning.[2]
For interning to work the interned objects must be immutable, since state is shared between multiple variables. String interning is a common application of interning, where many strings with identical values are needed in the same program.