-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copy On Write는 어떤 방식으로 동작하는지 설명하시오. #3
Comments
Swift 에서 Value Type or Reference Type Copy 방식
Copy - On - Write에 대해
Copy - On - Write의 장점
Copy - On - Write의 단점
📝 참고 사이트 |
Copy-on-Write란?Value Type의 복사를 하는 Collection Type(array, dictionary, string) 등에서 사용되는 기법이다. 원본 값이 복사될 때, 복사본은 바로 복사되지 않고 원본 값의 메모리 주소를 참조하다가, 복사된 값이 변경되는 시점에 독립적인 메모리 공간으로 복사된다. Copy-on-Write의 동작 방식
Copy-on-Write를 사용하는 이유값 복사를 하게되면 heap에 값이 저장되는 깊은 복사 방식을 채택하게 되는데, 매번 깊은 복사를 하게되면 높은 메모리 오버헤드가 발생한다. 따라서 Copy-on-Write 방식을 사용하여 복사가 필요한 시점, 즉 수정이 발생할 때만 복사를 수행함으로써 메모리를 효율적으로 관리할 수 있다. 📝 참고 |
Copy-On-Wirte (COW)Copy-On-Write 란 데이터간에 값 복사가 이루어질때, 바로 복사가 이루어 지지 않고 데이터 수정시에 값복사가 이루어지는 메커니즘을 의미한다. Copy-On-Write 동작 조건
Copy-On-Write 동작 과정
Copy-On-Write 의 이점단일 데이터가 아닌 복수 데이터를 복사한 후 수정이 없을 경우, 메모리 할당에 드는 오버헤드를 줄일 수 있어 성능에 도움을 준다. Copy-On-Write 의 단점데이터 복사후 첫 수정시에 새로운 메모리 할당이 이루어지고 값 복사가 이루어지므로 이때 실행속도가 저하될 수 있다. 📝 참고 사이트 |
Copy - On - Write(COW)란
Copy - On - Write(COW) 예제아래 코드에서 기본적으로 array1을 생성하고 array2에 할당한다. 여기서 Copy-on-write로 인해 복사되지 않으므로 둘 다 동일한 주소를 가리킴 import Foundation
func print(address o: UnsafeRawPointer ) {
print(String(format: "%p", Int(bitPattern: o)))
}
var array1: [Int] = [0, 1, 2, 3]
var array2 = array1
print(address: array1) //0x600000078de0
print(address: array2) //0x600000078de0
//아래와 같이 array2값이 변경될 때만 복사된다.
array2.append(4)
print(address: array2) //0x6000000aa100 Copy - On - Write(COW)의 단점
📝 참조 |
🗣️ Copy - On - Write 추가 공유
📝 참고 사이트 |
No description provided.
The text was updated successfully, but these errors were encountered: