String interning
Last updated
Last updated
In computer science, string interning is a method of storing only one copy of each distinct value, which must be . 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.
์ ์์ ๊ฐ์ด ์ ์ค๋ช ๋๊ณ ์๋ค. ํต์ฌ๋ง ์๋์ ์ฐ์๋ฉด ์๋์ ๊ฐ๋ค.
๋ฌธ์์ด ์ดํฐ๋์ด๋ ๋ถ๋ณ์ ์ ์ผ ๋ฌธ์์ด๋ก ๊ฐ ๋ฌธ์์ด copy ๋ฅผ ๋ณด๊ดํ๊ธฐ ์ํ ๋ฐฉ๋ฒ์ด๋ค. ๋ฌธ์์ด์ ์ธํฐ๋ ํ๋ ๊ฒ์ ๋ฌธ์์ด์ด ์๋ก ์์ฑ๋จ์ ์์ด์ ์๊ฐ ๋ณต์ก๋, ๊ณต๊ฐ ๋ณต์ก๋ ์ธก๋ฉด์์ ํจ์ฌ ํจ์จ์ ์ผ๋ก ๋ง๋ค์ด์ค๋ค. ๊ฐ๊ฐ์ ๊ตฌ๋ถ๋๋ ๊ฐ์ ๋ฌธ์์ด ํ์ ์ ์ฅ๋๋ค.
์ฝ๊ฒ ๋งํด์ ๋ฌธ์์ด์ ๋ด๋ถ์ ์ผ๋ก ๋ฌธ์์ด ํ์ ์บ์ฑ์ฒ๋ผ ์ ์ฅํด๋จ๋ค๊ฐ ๋์ผํ ๋ฌธ์์ด์ด ํ์ํ ๋ ์ด๋ฏธ ๋ง๋ค์ด์ง ๋ฌธ์์ด์ ๊ทธ๊ฒ์ด ์์ผ๋ฉด ๊ทธ ๊ฐ์ฒด๋ฅผ ๋ฐํํ๋ค๋ ๊ฒ์ด๋ค.
new String ์ ์ฌ์ฉํ ๊ฒฝ์ฐ ๋ฌธ์์ด ์ธํฐ๋์ ๋ฌด์ํ๊ฒ ๋๋ค. ๊ทธ๋์ hi1 ๊ณผ hi2 ์ ๊ฐ์ฒด๋ ๋๋ฑํ์ง๋ง ๋ค๋ฅธ ์ฐธ์กฐ๊ฐ์ ๊ฐ์ง๊ฒ ๋๋ค. ๋์ผ์ฑ์ด ๊นจ์ง๋ ๊ฒ์ด๋ค. ํ์ง๋ง hi3์ ๊ฒฝ์ฐ "hi" ๋ก ๊ฒฐ๊ณผ์ ์ผ๋ก h1 ๊ณผ ๋์ผํ๊ณ h1 ์์ฑ์ ์ธํฐ๋ ๋ ๋ฌธ์์ด์ ๋ฐ๋ผ๋ณด๊ฒ ๋์ด์ h3๊ณผ h1์ ์ฐธ์กฐ๊ฐ์ ๊ฐ์์ง๋ค.
์๋ ์ฝ๋๋ก๋ 76~77ms ์ด ๋์ค๊ณ ์๋ค. ๋ฌธ์์ด ํ์์ ๊บผ๋ด ์ฐ๋ ๊ฒ์ ํผํ๊ณ ์๋ก์ด ๊ฐ์ฒด๋ฅผ ์ผ๋ถ๋ฌ ๋ง๋ค๊ฒ ํ๋ค.
๋ฐ๋ฉด์ ์๋ ์ฝ๋๋ 1ms ์ด ์ฐํ๋ค. ๊ทธ๋ฅ ์ซ์๋ง์ผ๋ก ์๋๊ฐ 70๋ฐฐ ์ด์ ์ฐจ์ด๊ฐ ๋๋ค.