프로세스: 실행 중인 프로그램.
프로그램 실행을 위해 메모리 내에 코드, 데이터, 스택, 힙, U-영역 등의 영역(segments)이 필요.
프로세스 이미지:
프로세스가 메모리에 적재된 형태(아래 구조 참고).
int a = 1; static int b = 2;
) vs. 초기화되지 않은 데이터(long sum[1000];
)malloc
, new
등) 영역malloc
, calloc
, realloc
)void* malloc(size_t size);
— size 바이트만큼 메모리 할당, 시작 주소 반환void free(void* ptr);
— 할당된 메모리 해제void* calloc(size_t n, size_t size);
— n개, size 바이트씩 0으로 초기화void* realloc(void* ptr, size_t newsize);
— 기존 블록 크기 변경c
CopyEdit
char *ptr = (char*) malloc(40);
int *arr = (int*) malloc(10 * sizeof(int));
free(ptr);