> For the complete documentation index, see [llms.txt](https://leehyokyun.gitbook.io/openbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://leehyokyun.gitbook.io/openbook/1-4..md).

# 1-4. 연속 메모리 할당 기법

데이터를 저장하기 위한 페이지, 연속된 메모리 사용 방안에 대하여

### 1. 연속 메모리 할당 기법의 개념 정의

* 연속 메모리 할당 기법은 연속적인 것과 연결된(Linked) 개념을 모두 포함하는 범용적 메커니즘이다.
* 프로세스가 리스트, 배열 등 연속적인 혹은 연결된 메모리 공간과 주소를 필요로 하는 형태이거나 객체 등이 필요할 때, 운영체제 측에서 해당 프로세스에 연속적인 메모리를 할당하는 방법이다.
* 운영체제의 연속 메모리 할당 연산을 통해, 해당 프로세스는 말 그대로 물리 메모리 상의 연속적인 메모리 주소 공간을 점유하게 된다.

### 2. 고정 크기 메모리 할당과 단편화(Fragmentation) 현상

* 고정 크기 메모리 할당은 물리적인 메모리 공간을 고정된 일정한 크기로 미리 나누어 둔 후, 그 고정된 크기만큼 프로세스에 배정하는 방식이다.
* 자원의 한정성으로 인해 메모리 공간이 낭비되거나 할당되지 못하는 단편화 현상이 필연적으로 발생한다.
* 외부 단편화(External Fragmentation): 프로세스가 300MB의 메모리 공간을 필요로 하지만, 남아 있는 빈 메모리 공간들이 쪼개져 있어 연속적인 메모리 크기가 이에 부합하지 않아 자원을 할당하지 못하고 낭비되는 현상이다.
* 내부 단편화(Internal Fragmentation): 외부 단편화와 반대로, 분할된 고정 공간보다 작은 프로세스가 적재되어 오히려 더 큰 메모리를 할당하게 됨으로써, 할당된 분할 공간 내부에서 메모리 자원이 사용되지 못하고 그대로 낭비되는 상황이다.
* 가변 크기 할당 방식의 경우에도 메모리를 프로세스 크기에 맞게 가변적으로 할당할 수 있으나, 프로세스가 해제되고 생성되는 과정이 반복됨에 따라 자잘한 빈 공간들이 누적되어 외부 단편화가 동일하게 발생한다.

### 3. 운영체제의 메모리 배치 알고리즘 조건 및 특징

* 최초 적합(First Fit): 운영체제가 메모리 내의 빈 가용 공간들을 주소 순서대로 검색하다가, 프로세스를 수용할 수 있는 최초로 발견된 공간에 즉시 프로세스를 배치하는 방식이다. 탐색이 신속하게 완료된다는 특징을 가진다.
* 최적 적합(Best Fit): 운영체제가 메모리 내에 존재하는 모든 빈 공간을 전수 검색한 후, 프로세스의 크기와 가장 딱 맞아떨어지는(남는 공간이 가장 최소화되는) 공간을 선택하여 적재하는 방식이다. 공간 활용 측면에서 미세한 빈 공간을 아낄 수 있다.
* 최악 적합(Worst Fit): 최적 적합과 반대로 운영체제가 메모리 내의 모든 빈 공간을 전부 검색한 뒤, 가장 크기가 큰 빈 공간에 프로세스를 배치하는 방식이다. 배치 후 남는 가용 공간의 크기가 크게 유지되므로 다른 프로세스를 추가로 수용하기 용이하다는 관점을 취한다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://leehyokyun.gitbook.io/openbook/1-4..md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
