Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
SwiftのArrayは メモリで連続だよ!
Search
はるふ
May 25, 2018
Programming
0
49
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
250
Other Decks in Programming
See All in Programming
GraphQLサーバの構成要素を整理する #ハッカー鮨 #tsukijigraphql / graphql server technology selection
izumin5210
4
820
ゆるい個人開発のススメ
kuroppe1819
10
990
Milestoner
bkuhlmann
1
410
Git Lint
bkuhlmann
4
750
R言語の環境構築と基礎 Tokyo.R 112
bob3bob3
0
260
Code Reviews
bkuhlmann
4
890
PHPの次期バージョンはこの時期どうなっているのか - Internalsの開発体制について - PHPカンファレンス小田原
youkidearitai
PRO
1
190
Micro Frontends for Java Microservices - Devnexus 2024
mraible
PRO
0
490
MetricKitで予期せぬ終了を検知する話 / Detect unexpected termination with MetricKit
nekowen
1
180
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
130
Prepare for Jakarta EE 11 - Performance and Developer Productivity
ivargrimstad
0
740
1BRC--Nerd Sniping the Java Community
gunnarmorling
0
340
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
17
6.4k
Become a Pro
speakerdeck
PRO
11
4.5k
4 Signs Your Business is Dying
shpigford
175
21k
What's new in Ruby 2.0
geeforr
337
31k
GitHub's CSS Performance
jonrohan
1025
450k
Building Better People: How to give real-time feedback that sticks.
wjessup
355
18k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
2
1.3k
RailsConf 2023
tenderlove
4
540
Adopting Sorbet at Scale
ufuk
68
8.6k
Web development in the modern age
philhawksworth
202
10k
The Cost Of JavaScript in 2023
addyosmani
16
3.9k
Documentation Writing (for coders)
carmenintech
60
3.9k
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