-
MMAP 뜻과 사용 예제개발 팁/Embedded 2018. 4. 25. 15:22반응형
MMAP란 무엇인가?
mmap는 유닉스 시스템 콜로, 파일이나 디바이스를 메모리에 매핑시킨다. 즉 Memory-mapped file I/O라고 보면 된다. 실제 구현은 demand paging으로 이루어진다. 사용이 끝나면 munmap 콜을 불러줘 야 한다. Demang Paging이란 가상 메모리의 일종으로 디스크의 페이지를 메모리에 복사하여 사용한다. 이 동작은 특정 위치를 접근하려 할 때 특정 위치가 메모리에 존재하지 않는 경우, 즉 Page Fault 상황에서 이루어진다.
사용 예제
const char str1[] = "string1";
char *zero;
fd = open("dev/zero", O_RDWF, 0);
zero = (char*)mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
strcpy (zero, str1);
printf ("PID %d: \tzero-backed %s\n", getpid(), zero);
munmap (zero, 4096);
close (fd);
출처
https//en.wikipedia.org/wiki/Mmap
https://en.wikipedia.org/wiki/Demand_paging
반응형'개발 팁 > Embedded' 카테고리의 다른 글
우분투(16.04 LTS)에 파이썬 3.6 설치하기 (0) 2018.04.16 ARM9 assembly 어셈블리 source - SourceInsight 소스인사이트 파싱 Parsing File(CLF) (0) 2017.11.13 ARM MBED 엠베드 7 세그먼트(Grove 4-Digit Display) 구동 방법 (0) 2017.11.12 ARM 엠베드 MBED 백색잡음 White Noise 생성 (0) 2017.11.12 ARM MBED 엠베드 핀이름 헤더 파일 찾기 (0) 2017.11.12