- 전자회로에서 데이터의 상태나 명령어를 기록하는 장치
- 보통 RAM (Random Access Memory) 으로 일컫기도 하는데, CPU가 메모리에 올라와있는 작업들을 실행하기 때문에, 메모리가 클 수록 더 많은 일을 동시에 수행할 수 있다
계층
- 레지스터 - CPU 안에 있는 작은 메모리, 제일 비싸고 용량도 적지만 가장 빠르다
- 캐시 - 데이터를 미리 복사해놓은 임시 저장소
- 주기억장치 - 실제 메모리 RAM을 가리킨다
- 보조기억장치 - HDD, SDD를 일컫는다
캐시
- 메모리와 레지스터, CPU간의 속도 차이가 너무 커서, 중간에 속도 병목을 해결하기 위해 구축한 계층
- 캐시는 자주 사용하는 데이터를 기반으로 설정해야 하는데, 자주 사용하는 근거는 아래 두 가지가 있다
- 시간 지역성 - 최근 사용한 데이터에 다시 접근하는 특성
- 반복문에서 주로 i 변수를 쓰는데, i로 ++ 해주면서 접근하는걸로 이해하면 된다
- 공간 지역성 - 최근 접근한 데이터의 공간에 접근하는 특성
- 반복문으로 어떤 합 또는 배열에 넣는다고 칠 때, 접근하는 변수들로 이해하면 된다
- 소프트웨어에선 웹 브라우저에서 많이 사용하는데, 쿠키, 로컬 스토리지, 세션 스토리지 등이 있다
- 쿠키 - 만료 기간이 있는 K-V 저장소, 보통은 서버에서 기간을 정한다
- 로컬 스토리지 - 만료 기간이 없는 K-V 저장소, 브라우저를 껏다 켜도 유지된다
- 세션 스토리지 - 로컬 스토리지와 유사하지만 브라우저 탭 단위로 유지되며, 탭이 닫히면 세션 스토리지 데이터도 삭제된다
- 데이터베이스에선 메인 DB 앞에 캐싱 계층을 별도로 두어 성능 관리를 하는데, 주로 Redis가 많이 쓰인다
관리
- OS의 대표 기능 중 하나가 메모리 관리인데, 한정된 메모리를 어떻게 활용하는지를 나타낸다
가상 메모리
- Virtual Memory, 메모리 관리 기법 중 하나로 컴퓨터가 실제 사용 가능한 메모리를 추상화하여 사용자에게 큰 메모리로 보여지게 만든다
- 이때 가상 메모리와 실제 메모리는 주소 매핑이 되어 있으며, 유저는 실제 메모리 주소를 의식할 필요 없이 프로그램을 실행할 수 있게 된다