Presentation is loading. Please wait.

Presentation is loading. Please wait.

25장. 메모리 관리와 동적 할당.

Similar presentations


Presentation on theme: "25장. 메모리 관리와 동적 할당."— Presentation transcript:

1 25장. 메모리 관리와 동적 할당

2 25-1 C 언어의 메모리 구조 스택, 힙 그리고 데이터 영역 프로그램의 실행을 위해 기본적으로 할당하는 메모리 공간
프로그램의 실행을 위해 기본적으로 할당하는 메모리 공간 컴파일 타임에 함수에서 요구하는 스택의 크기 결정 되어야 함 그림 25-1

3 25-1 C 언어의 메모리 구조 그림 25-2 void fct1(int); void fct2(int); int a=10;
int b=20; int main (void) { int m=123; fct1(m); fct2(m); return 0; } void fct1(int c){ int d=30; void fct2(int e){ int f=40; 그림 25-2

4 25-1 C 언어의 메모리 구조 배열의 선언 배열의 길이 선언은 상수!
컴파일 타임에 요구되는 메모리 공간의 크기를 결정지어야 하므로 /* probArray.c 의 일부 */ void function(int i) { int array[i]; } void function(void) { int i=10; int array[i]; }

5 25-2 메모리 동적 할당 메모리 동적 할당 동적 할당된 메모리 공간의 소멸
25-2 메모리 동적 할당 메모리 동적 할당 런 타임에 메모리 공간의 크기를 결정지어서 할당 (힙 영역에 할당) 동적 할당된 메모리 공간의 소멸 #include <stdlib.h> void* malloc(size_t size) 성공 시 할당된 메모리의 첫 번째 주소 리턴, 실패 시 NULL 포인터 리턴 #include <stdlib.h> void free(void* ptr)

6 25-2 메모리 동적 할당 malloc 함수의 활용 malloc&free.c, ProbArray2.c 참조 그림 25-7


Download ppt "25장. 메모리 관리와 동적 할당."

Similar presentations


Ads by Google