C++ AdventCalendarの12日目 普段私はWEBのフロントエンドを仕事にしている。 つまり使う言語はjavascript/typescript等のScript言語だ。 ただ前職や趣味、OSS等でC++によく触っていたので昔実装したmallocの話をすることにした。 mallocとは mallocとはC言語のstdlib.hに含まれるメモリ割り当て関数のことで、 C++やその他の多くの言語で内部的に利用されている。 ヒープを割り当てる方法はいくつかあるが、このmallocがもっともメジャーといえるだろう。 mallocを再実装した 今回はmallocを自分で再実装してちょっと早くした話を書く。 再実装した理由は色々あるが最も大きな理由はただの好奇心。 yatscというtypescriptのコンパイラをC++で書こうと思って実装を始めたときに作った。 ただしyatsc自体は未完で
2. 今日は何の話? libc でもっとも良く使われる関数、 malloc と free の実装の解説 もっと一般的に言うと、プロセスのアドレス空間のうち、 heap 領域とよばれる、場所を操作する関数の説明 解説というと聞こえはいいが、そんな大層なものじゃない 3. Linux での process address space model kernel stack text mmap data bss heap 矢印はデータ量の増加と ともに、伸びる方向 使用中 使用中 使用中 今日は、ここ、 heap と呼ばれる領域のお話 low high free free free 4. 古典的 malloc プログラミング言語 C (いわゆる K&R) で紹介された初期の Unix の malloc 実装 使用中 使用中 使用中 free listの head 使用中 ・ free list を
dlmalloc, tcmalloc, jemallocについて,以下の各記事を読めば各mallocのアルゴリズムはわかるはず. dlmalloc Linuxの一部やAndroidのDalvik VMで利用されている.シンプルながらうまく考えられている. チャンク(連続空き領域1つ)の境界と構造体の境界が違う所が罠. http://g.oswego.edu/dl/html/malloc.html http://mkosaki.blog46.fc2.com/blog-entry-241.html にわかりやすい講演資料が,と思ったら動画がprivateになってる… tcmalloc thread-caching malloc. Googleで利用されている. スレッドがキャッシュ持つのでfreeしてもメモリ利用量が減らない!のが罠. http://goog-perftools.sourcef
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く