1 / 7

Memory Layout

Memory Layout. 2006242108 전중현. Memory 구조. Text 영역 Program 코드영역 (CPU 에 의해 수행되는 기계어 명령어들이 모여있는 곳 ) Data 영역 전역변수와 정적 (static) 변수가 할당된 곳 . 프로그램 시작과 동시에 할당되고 프로그램이 종료되어야 메모리에서 소멸된다 . (1) 초기화된 데이터영역 . (2) 비초기화된 데이터영역 . Bss (block started by symbol) 라고도 함 Stack 영역

Jims
Télécharger la présentation

Memory Layout

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Memory Layout 2006242108 전중현

  2. Memory 구조 • Text 영역 Program코드영역 (CPU에 의해 수행되는 기계어 명령어들이 모여있는 곳) • Data 영역 전역변수와 정적(static)변수가 할당된 곳. 프로그램 시작과 동시에 할당되고 프로그램이 종료되어야 메모리에서 소멸된다. (1) 초기화된 데이터영역. (2) 비초기화된 데이터영역. Bss(block started by symbol)라고도 함 • Stack 영역 지역변수와 매개변수가 저장되는 곳. 이 영역에 할당된 변수는 함수 호출이 끝나면 사라진다. • Heap 영역 동적 메모리 할당하는 곳. 프로그래머가 할당 및 해제를 해주어야 한다.

  3. #include <stdio.h> #include <malloc.h> static int a, b=10; intc,d=10; void foo(int x) { int y, *f = malloc(10); static intz,v=10; printf("foo함수의초기화된내부변수x의메모리위치: 0x%X\n",&x); printf("foo함수의비초기화내부변수y의메모리위치: 0x%X\n\n",&y); printf("foo함수의비초기화정적변수z의메모리위치: 0x%X\n",&z); printf("foo함수의초기화된정적변수v의메모리위치: 0x%X\n\n",&v); printf("foo함수의동적할당된f의메모리위치: 0x%X\n",&(*f)); printf("foo함수의포인터변수f의메모리위치: 0x%X\n\n",&f); } void main() { int *p, q, r=10; printf("main함수의메모리위치: 0x%X \n",&main); printf("foo함수의메모리위치: 0x%X \n\n",&foo); printf("비초기화정적변수a의메모리위치: 0x%X \n",&a); printf("초기화된정적변수b의메모리위치: 0x%X \n\n",&b); printf("비초기화전역변수c의메모리위치: 0x%X \n",&c); printf("초기화된전역변수d의메모리위치: 0x%X \n\n",&d); p = malloc(10); printf("main함수의비초기화내부변수q의메모리위치: 0x%X \n",&q); printf("main함수의초기화된내부변수r의메모리위치: 0x%X \n\n",&r); printf("동적할당된변수*p의메모리위치: 0x%X \n",&(*p)); printf("main함수의포인터변수p의메모리위치: 0x%X \n\n",&p); foo(1); free(p); } Memory b foo a v c d f z *p *f q r p x y main Text영역 0x418000 0x13FF64 0x13FF58 0x35D20 0x418154 0x41817C 0x418004 0x418008 0x41112C 0x41114A 0x35D58 0x13FF54 0x13FF48 0x13FF60 0x13FF74 0x418150 Data영역 Bss영역 Heap영역 Stack영역

  4. 프로그램 출력결과

  5. Text영역 Data영역 Bss영역 Heap영역 Stack영역

  6. QnA?!

More Related