Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SwiftのArrayは メモリで連続だよ!
Search
はるふ
May 25, 2018
Programming
0
63
SwiftのArrayは メモリで連続だよ!
2018/5/25
京都Devかふぇ #1 〜モバイル〜
https://kyoto-dev-cafe.connpass.com/event/85513/
はるふ
May 25, 2018
Tweet
Share
More Decks by はるふ
See All by はるふ
AltConf report - Hakata.swift #8
ha1f
2
370
Other Decks in Programming
See All in Programming
LLM Çağında Backend Olmak: 10 Milyon Prompt'u Milisaniyede Sorgulamak
selcukusta
0
120
안드로이드 9년차 개발자, 프론트엔드 주니어로 커리어 리셋하기
maryang
1
120
モデル駆動設計をやってみようワークショップ開催報告(Modeling Forum2025) / model driven design workshop report
haru860
0
270
AIコードレビューがチームの"文脈"を 読めるようになるまで
marutaku
0
360
なあ兄弟、 余白の意味を考えてから UI実装してくれ!
ktcryomm
11
11k
251126 TestState APIってなんだっけ?Step Functionsテストどう変わる?
east_takumi
0
320
チームをチームにするEM
hitode909
0
340
AIの誤りが許されない業務システムにおいて“信頼されるAI” を目指す / building-trusted-ai-systems
yuya4
6
3.7k
これならできる!個人開発のすゝめ
tinykitten
PRO
0
110
エディターってAIで操作できるんだぜ
kis9a
0
730
React Native New Architecture 移行実践報告
taminif
1
160
AIコーディングエージェント(Gemini)
kondai24
0
230
Featured
See All Featured
Why Our Code Smells
bkeepers
PRO
340
57k
GraphQLの誤解/rethinking-graphql
sonatard
73
11k
The World Runs on Bad Software
bkeepers
PRO
72
12k
The Language of Interfaces
destraynor
162
25k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
970
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.2k
Practical Orchestrator
shlominoach
190
11k
Making Projects Easy
brettharned
120
6.5k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.6k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
BBQ
matthewcrist
89
9.9k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Transcript
SwiftͷArray ϝϞϦͰ࿈ଓͩΑʂ Δ; - LINE Fukuoka 2018/5/25 ژDev͔;͐ #1 ʙϞόΠϧʙ
iOS Engineer / LINE Fukuoka Δ; @_ha1f ࢁޱ ஐੜ https://github.com/ha1f
https://github.com/koher/EasyImagy Motivation • ϐΫηϧͷArrayΛ༻ҙ • RGBAͷϏοτϚοϓΛඳը
ͳΜͩ͜Εʂ Arrayʹ͍ͭͯௐͯΈΔ
• Array͋ΔαΠζͷϝϞϦྖҬΛ֬อ͢Δ = capacity • capacityΛ͑ͯཁૉΛՃͨ͠ͱ͖ɺഒͷϝϞϦྖҬΛ ֬อͯ͠ɺͱͷΛίϐʔ͢Δ https://developer.apple.com/documentation/swift/array Array-Growing the
Size of an Array (ҙ༁)
ͬͯΈΔ appendΛ܁Γฦͯ͠ɺ 1. capacityΛϓϩοτ 2. ΠϯλʔόϧΛϓϩοτ
• capacity(ॎ)ͷϓϩοτ • 0, 2, 4, 8, 16, 32, …
…, 188, 380, 764, … • ઌ಄ΞυϨεΛΈΔͱɺ࣮ ࡍʹมΘ͍ͬͯΔ Append-capacity ճ
• ഒʑ͙Β͍ͷλΠϛϯάͰ εύΠΫ • ͍΄Ͳίϐʔ࣌ؒ↑ Append-interval ճ
ଞͷૢ࡞ͯ͠ ϝϞϦ্࿈ଓͳͷʁ υΩϡϝϯτݟ͔ͭΒͳ͍ͷͰɺ࣮ࡍʹࢼͯ͠ΈΔ
• 0..<100 ͷArray Λ༻ҙ • 50൪Λremove • ઌ಄ɺ50൪ɺ࠷ޙඌͷΞυϨεΛදࣔ REMOVE Optional(0x0000000100e30c60)
Optional(0x0000000100e30df0) Optional(50) Optional(0x0000000100e30f78) Optional(0x0000000100e30c60) Optional(0x0000000100e30df0) Optional(51) Optional(0x0000000100e30f70)
• 0..<100 ͷArray Λ༻ҙ • 50൪Λremove • ઌ಄ɺ50൪ɺ࠷ޙඌͷΞυϨεΛදࣔ REMOVE Optional(0x0000000100e30c60)
Optional(0x0000000100e30df0) Optional(50) Optional(0x0000000100e30f78) Optional(0x0000000100e30c60) Optional(0x0000000100e30df0) Optional(51) Optional(0x0000000100e30f70) ઌ಄Ґஔಉ͡ ΞυϨεಉ͕͕ͩ͡ҧ͏ ޙΖInt1ͭ ζϨͯΔ
আͨ͠ͱ͜ΑΓޙΖଆΛશ෦ͣΒ͍ͯ͠Δ Remove લଆ ޙଆ લଆ ཁૉ ޙଆ
• 10ສݸͷྻ • ઌ಄আ܁Γฦִͯؒ͠Λ ϓϩοτ • શମతʹԼ͕͍ͬͯ͘ • ΪβΪβͷཧ༝ෆ໌ REMOVE
• (insertඈ͠·͕ͨ͠) • (ఆੑతͳ͔ͯ͠͠ͳ͍͚Ͳ) • SwiftͷArray(ૢ࡞ޙͰ)ϝϞϦ্Ͱ࿈ଓ (※MemoryLayout<T>.strideͷઆ໌ʹΑΓ࣮֬ͳώϯτ͕͋ͬͨ) • ಈ࡞Λҙࣝ͢Δͱ͘ͳΔ͔ʁʢreserveCapacity, …ʣ
·ͱΊ
THANK YOU