sbrk(), brk() 메모리 할당(malloc) 시 호출되는 시스템 콜

참조 :
https://en.wikipedia.org/wiki/Sbrk
http://man7.org/linux/man-pages/man2/brk.2.html
https://pubs.opengroup.org/onlinepubs/7908799/xsh/brk.html

 메모리 관리에 사용되는 기본적인 시스템 콜 명령어

int brk(void *addr);

The brk() function sets the break value to addr and changes the allocated space accordingly.

brk() 는 addr 주소 위치에 program break (현재 프로세스의 data segment의 끝부분 바로 다음 자리)를 설정한다.
 program break )를 설정한다.

 program break 의 위치를 옮김으로써 메모리를 할당하거나 반환한다.

 성공시 brk() 는 0을 반환하고 실패시 -1 을 반환한다.



void *sbrk(intptr_t increment);

The sbrk() function adds incr bytes to the break value and changes the allocated space accordingly. If incr is negative, the amount of allocated space is decreased by incr bytes. The current value of the program break is returned by sbrk(0).

 sbrk() 는 program break에 increment 만큼 더한 뒤 그만큼 할당된 메모리를 변경한다. 만약에 increment가 음수이면 할당된 메모리는 감소한다.

 성공시 sbrk()는 이전 program break 주소를 반환하며(새로 메모리가 할당되었을 때 이전 program break는 할당된 메모리의 시작위치)  실패 시 (void *) -1을 반환한다.

댓글

이 블로그의 인기 게시물

Unity - Dialogue 시스템을 구현할 때 유용한 무료 에셋

Unity - 메타 파일

Unity - 라이브러리 폴더