Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
プロセスへのメモリ割り当て2-Pythonのようなナウい言語ではどうやってメモリ獲得するのか
Search
Satoru Takeuchi
PRO
July 10, 2024
200
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
プロセスへのメモリ割り当て2-Pythonのようなナウい言語ではどうやってメモリ獲得するのか
以下動画のテキストです。
https://youtu.be/aI7ancLZUTQ
Satoru Takeuchi
PRO
July 10, 2024
More Decks by Satoru Takeuchi
See All by Satoru Takeuchi
119-多機能ファイルシステムBtrfs_のコピー.pdf
sat
PRO
1
68
Linuxカーネルの インタフェースは変わりうる?
sat
PRO
1
93
あなたの知らないバージョン命名規則
sat
PRO
3
900
Rook: Intro and Deep Dive with Ceph
sat
PRO
1
64
Machine Check Exception
sat
PRO
2
66
バイナリダンプの模様を読む
sat
PRO
0
89
cpコマンドはディスク上でデータを コピーしないことがある
sat
PRO
3
87
114-ファイルのshallow_copy.pdf
sat
PRO
2
57
113-Btrfsのスナップショット.pdf
sat
PRO
0
40
Featured
See All Featured
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
880
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
460
Practical Orchestrator
shlominoach
192
12k
Being A Developer After 40
akosma
91
590k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
460
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
690
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
380
Transcript
プロセスへのメモリ割り当て(2) Pythonのようなナウい言語では どうやってメモリ獲得するのか Jul. 10th, 2024 Satoru Takeuchi X: satoru_takeuchi
1
はじめに • 前回の動画で学んだこと ◦ プロセスへのメモリ割り当てには mmapというシステムコールを使う • 疑問 ◦ Pythonのようなナウい言語はメモリやらアドレスを直接意識せずに変数を操作できる
◦ ナウい言語で変数を動的に作成すると何が起こる ? • 備考 ◦ 📝 Pythonでも抽象化された形で mmapを呼ぶことはできます 2
答え • 言語処理系が頑張って、変数を作るときに裏でmmapを呼んでいます • 雑に書くと以下のようになっている ◦ プログラム作成時に変数を格納するためのメモリ領域を一定量獲得しておく ◦ 変数が獲得されるたびに確保済みのメモリ領域を一部ずつ切り出す ◦
確保済みの領域が足りなくなれば mmapを発行して領域の数を増やす 3
Pythonの場合は? • Pythonの公式実装(CPython)はCプログラム • 処理系のメモリ獲得の方法 ◦ mmapを呼ぶ ◦ C標準のメモリ獲得関数 mallocを呼ぶ
▪ その裏側ではC標準ライブラリ(glibc)がmmapを呼んでいる 4
実機確認 • Pythonで大きなメモリ領域を獲得した際にmmapが発行されることを確認 • mem.pyプログラム ◦ メモリ獲得前であることを示すメッセージを表示する ◦ メモリ獲得後であることを示すメッセージを表示する •
mem.pyをstrace経由で動かしたとき、2つのメッセージが表示される間にmmapが 発行されるかを確認。 5
まとめ PythonスクリプトもC言語の処理系を通してmmapによってメモリを獲得 6