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
61
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
340
Other Decks in Programming
See All in Programming
スタートアップの急成長を支えるプラットフォームエンジニアリングと組織戦略
sutochin26
0
160
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
340
LT 2025-06-30: プロダクトエンジニアの役割
yamamotok
0
640
WindowInsetsだってテストしたい
ryunen344
1
210
0626 Findy Product Manager LT Night_高田スライド_speaker deck用
mana_takada
0
130
GitHub Copilot and GitHub Codespaces Hands-on
ymd65536
1
130
Is Xcode slowly dying out in 2025?
uetyo
1
240
ReadMoreTextView
fornewid
1
490
LINEヤフー データグループ紹介
lycorp_recruit_jp
0
1.6k
Java on Azure で LangGraph!
kohei3110
0
170
20250704_教育事業におけるアジャイルなデータ基盤構築
hanon52_
1
140
Google Agent Development Kit でLINE Botを作ってみた
ymd65536
2
210
Featured
See All Featured
Fireside Chat
paigeccino
37
3.5k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
The Cult of Friendly URLs
andyhume
79
6.5k
GitHub's CSS Performance
jonrohan
1031
460k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Building Adaptive Systems
keathley
43
2.6k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
How to Ace a Technical Interview
jacobian
277
23k
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