[C++] malloc/free์ ํด๋์ค
malloc๊ณผ free๋ ๊ฑฐ์ C ์ ์ฉ์ ๋ฉ๋ชจ๋ฆฌ ํ ๋น ๊ธฐ๋ฅ์ด์ง๋ง, ์ด์จ๋ C++์์๋ ์ฌ์ฉํ ์๋ ์๋ค.
ํ์ง๋ง new/delete ์ฐ๋ฏ์ด ์จ์๋ ์๋๋ค.
malloc/free ์์ ๋ง ๊ทธ๋๋ก ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํ ๋นํ๊ณ ํด์ ํ๋ ๊ฒ๋ง ํ๊ณ , ์๋ฌด๊ฒ๋ ํ์ง ์๊ธฐ ๋๋ฌธ์ด๋ค.
๊ทธ๋์ ์๋์ฒ๋ผ new/delete๋ฅผ ์ฌ์ฉํ๋ฉด ์์ฑ/์ญ์ ์๋ง๋ค ์์ฑ์์ ์๋ฉธ์๋ฅผ ์๋์ผ๋ก ํธ์ถํด์ฃผ์ง๋ง
malloc/free๋ ๊ทธ๋ ์ง ์๋ค. ๊ทธ๋ฅ ๋ฑ ๋ฉ๋ชจ๋ฆฌ ๊ณต๊ฐ๋ง ๋๋ค ์น์ฐ๋๊ฒ ๋ค๋ผ์ ๊ทธ๋ ๋ค.
malloc/free๋ก๋ ํด๋์ค๊ฐ ์ ์๋์ํ ๋ก ํ๋ ค๋ฉด, ์๋์ฒ๋ผ ์์ฑ์์ ์๋ฉธ์๋ฅผ ๋ช
์์ ์ผ๋ก ๋ถ๋ฌ์ค์ผํ๋ค.
์ด๋ฐ์ง์ ๊ตณ์ด ํ๊ณ ์ถ์๊ฐ?
์ฐธ์กฐ
https://stackoverflow.com/questions/2995099/malloc-and-constructors