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
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
380
Other Decks in Programming
See All in Programming
生成AIを使ったコードレビューで定性的に品質カバー
chiilog
1
270
並行開発のためのコードレビュー
miyukiw
0
260
Grafana:建立系統全知視角的捷徑
blueswen
0
330
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
140
要求定義・仕様記述・設計・検証の手引き - 理論から学ぶ明確で統一された成果物定義
orgachem
PRO
1
150
IFSによる形状設計/デモシーンの魅力 @ 慶應大学SFC
gam0022
1
310
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
190
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
CSC307 Lecture 05
javiergs
PRO
0
500
副作用をどこに置くか問題:オブジェクト指向で整理する設計判断ツリー
koxya
1
610
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
1
980
組織で育むオブザーバビリティ
ryota_hnk
0
180
Featured
See All Featured
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
1
53
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
650
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
200
Git: the NoSQL Database
bkeepers
PRO
432
66k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
230
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
370
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
220
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
0
210
Code Review Best Practice
trishagee
74
20k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Become a Pro
speakerdeck
PRO
31
5.8k
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