Questions tagged [string-interning]

A string pool allows a runtime to save memory by preserving immutable strings in a pool, so that instances of common strings can be reused throughout the application instead of creating multiple instances of them.

In computer science, string interning is a method of storing only one copy of each distinct string value, which must be immutable. Interning strings makes some string processing tasks more time- or space-efficient at the cost of requiring more time when the string is created or interned. The distinct values are stored in a string intern pool.

163 questions
0
votes
2 answers

Why string intern in the symbol table of the Tiger Book?

In Chapter 5.1.4, Modern Compiler Implementation in Java: public class Symbol { private String name; private Symbol (String n) { name = n; } private static java.util.Dictionary dict = new java.util.Hashtable(); public String toString() {…
abcdabcd987
  • 2,043
  • 2
  • 23
  • 34
0
votes
2 answers

String creation in Pool and Heap

Have few doubts in String, I may be wrong with certain statements as i am writing this based on my understanding from various articles on Internet, please bear with me. When we do String str1 = new String ("newStr1");. This creates 2 string…
pranav
  • 421
  • 1
  • 11
  • 27
0
votes
1 answer

What all utilizes an intern pool?

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…
Ethan
  • 144
  • 11
0
votes
2 answers

When is interning during done during compile time or run-time? The reason for such behaviour in code? Problems in BlueJ?

Value of string is 12 .And 'string_input' store the input number string is declared and initialized in the code while string_input is inputed by the user during run-time Case…
sedflix
  • 226
  • 4
  • 13
0
votes
0 answers

Interning longs

Python's intern function lets you save memory if you have a lot of copies of the same string floating around, by replacing them all with references to a single object. I have a similar situation, except that instead of strings I'm dealing with…
Taymon
  • 24,950
  • 9
  • 62
  • 84
0
votes
3 answers

The == operator in Java

the following is true in Java "abc"=="abc" Why? The two Strings are two different objects, they should not have the same object identity?
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
0
votes
2 answers

How to avoid slow equals for interned objects?

I'm creating a few rather big objects and many of them are duplicates. So I thought about using Guava's Interner for them and always work with the interned object only (i.e., each object gets interned just after creation). It occurred to me that…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
0
votes
6 answers

Is converting int to a String counted as Autoboxing?

AFAIK When Java automatically converts a primitive type into wrapper class object than its called autoboxing because primitive is boxed into wrapper class. So is int test = 3; String str = String.valueOf(test); counted as autoboxing? Reason to…
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
-1
votes
1 answer

Does python use interning on generator objects? Weird behaviour with (i for i in range(n))

Why do these two loops not give the same result? (Yes, I know the second version is bad style. But I'd still expect it to give the same output.) gen1 = range(3) gen2 = range(3) print("First attempt") for i in gen1: for j in gen2: …
Alexander Hanysz
  • 791
  • 5
  • 15
-1
votes
3 answers

Why isn't `str(1) is '1'` `True` in Python?

I'm not asking about the difference between == and is operators! I am asking about interning or something..! In Python 3.9.1, >>> str(1) is '1' :1: SyntaxWarning: "is" with a literal. Did you mean "=="? False >>> '1' is '1' :1:…
dkssud
  • 125
  • 2
-1
votes
2 answers

Why does String.IsInterned return a string

I see that String.Intern will actually add a string to the intern-pool and String.IsInterned will return the reference to that corresponding interned string. This makes me wonder: Why does IsInterned return the referenced interned string and not a…
sean.net
  • 735
  • 8
  • 25
-1
votes
2 answers

Why java compiler does not interns arrays?

Consider the below code String s1 = "testString"; String s2 = "testString"; if(s1 == s2)System.out.println("equals!"); it prints equals!, (I am aware of String interning by the compiler) String[] s1 = {"testString","teststring2"}; String[] s2 =…
Arthas
  • 145
  • 1
  • 12
-1
votes
1 answer

what is Intern() in java?

public static void main(String[] args) { String literalstr = "ABC"; String literalstr2 = "ABC"; String str = new String("ABC"); String str2 = new String("ABC"); if (literalstr == literalstr2) { System.out.println("Literal…
loknath
  • 1,362
  • 16
  • 25
1 2 3
10
11