07-02 03:26
Notice
Recent Posts
Recent Comments
07-02 03:26
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Archives
Today
Total
관리 메뉴

pear

[iOS]Swift Value Memory Study 본문

iOS/swift

[iOS]Swift Value Memory Study

pearlab 2023. 6. 16. 10:27

스위프트 메모리 타입 요약

[High]

Stack

Dynamic 

Heap

BSS

GVAR

TEXT

[Low]

 

value type

dump(variable:)

dump(with:)

dump(object:)

 

EX) String

stack 16byte 할당

heap 문자열 할당(짧은 문자열은 stack영역도 사용)

dump(with:)

 

copy-on-write

 

 

Collection Heap

 

print(MemoryLayout<String>.size)//16

 

var fString = "a"

var sString = "bb"

print(MemoryLayout.size(ofValue: fString)) //16

print(MemoryLayout.size(ofValue: sString)) //16

 

주어진 instance 의 memory footprint 를 리턴하고, pointer나 class 인스턴스에 대해서는 reference data의 size 와 상관없이 동일한 memory footprint 를 return 한다.

 

copy on write

수정 시점에는 copy-object를 사용하고 instance공유(origin-object 메모리 주소를 참조) 수정 후 변경된 데이터를 반영

 

고정된 Reference Type Value 메모리는 Heap영역에 할당 될 수도 있다.

 

 

 

https://medium.com/@jungkim/%EC%8A%A4%EC%9C%84%ED%94%84%ED%8A%B8-%ED%83%80%EC%9E%85%EB%B3%84-%EB%A9%94%EB%AA%A8%EB%A6%AC-%EB%B6%84%EC%84%9D-%EC%8B%A4%ED%97%98-4d89e1436fee

 

스위프트 타입별 메모리 분석 실험

struct와 class 가 메모리 영역을 어디를 사용하는지 분석한 실험 결과

medium.com

 

https://www.freecodecamp.org/news/the-story-of-one-mother-two-sons-value-type-vs-reference-type-in-swift-6e125af2d5d0/

 

The story of one mother & two sons: value type vs reference type in Swift

Swift is a mother?and it has two sons ?- Value Type ??‍♀️Reference Type ?‍♂️But what are their characteristics??‍♂️ Do they behave the same or opposite to each other? ?‍♂️ Swift is a multi-paradigm programming language developed by

www.freecodecamp.org

https://swiftrocks.com/memory-management-and-performance-of-value-types

 

Memory Management and Performance of Value Types

It's very likely that you asked yourself at least once in your iOS career what's the difference between a struct and a class. While realistically the choice between using one or another always boils down to value semantics versus reference semantics, the p

swiftrocks.com