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
62
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
360
Other Decks in Programming
See All in Programming
オープンソースソフトウェアへの解像度🔬
utam0k
16
3k
Le côté obscur des IA génératives
pascallemerrer
0
150
はじめてのDSPy - 言語モデルを『プロンプト』ではなく『プログラミング』するための仕組み
masahiro_nishimi
2
580
Server Side Kotlin Meetup vol.16: 内部動作を理解して ハイパフォーマンスなサーバサイド Kotlin アプリケーションを書こう
ternbusty
3
210
私はどうやって技術力を上げたのか
yusukebe
44
19k
実践Claude Code:20の失敗から学ぶAIペアプログラミング
takedatakashi
14
4.9k
overlayPreferenceValue で実現する ピュア SwiftUI な AdMob ネイティブ広告
uhucream
0
190
Things You Thought You Didn’t Need To Care About That Have a Big Impact On Your Job
hollycummins
0
230
Flutterで分数(Fraction)を表示する方法
koukimiura
0
130
Pull-Requestの内容を1クリックで動作確認可能にするワークフロー
natmark
2
520
AI Coding Meetup #3 - 導入セッション / ai-coding-meetup-3
izumin5210
0
3.3k
Leading Effective Engineering Teams in the AI Era
addyosmani
7
460
Featured
See All Featured
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.5k
Leading Effective Engineering Teams in the AI Era
addyosmani
7
460
Rebuilding a faster, lazier Slack
samanthasiow
84
9.2k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
127
53k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.5k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
What's in a price? How to price your products and services
michaelherold
246
12k
Building a Modern Day E-commerce SEO Strategy
aleyda
44
7.8k
Optimizing for Happiness
mojombo
379
70k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
Building Better People: How to give real-time feedback that sticks.
wjessup
369
20k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.6k
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