Skip to content

Instantly share code, notes, and snippets.

@kjunichi
Last active September 1, 2016 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kjunichi/20c437277cfd36515ea9 to your computer and use it in GitHub Desktop.
Save kjunichi/20c437277cfd36515ea9 to your computer and use it in GitHub Desktop.

思いついたこと

mrb_hash_new

するメソッドをCで実装して、これをrubyでこんな感じにしたらどうなるか

c = 0
while c < 10000 do
  h = MyClass.mygetHash
  p h
  c += 1
end

期待

メモリ使用量が増加し無い事

GCのタイミングや、GCを強制実行するには

GC.start

という記述がQiitaにあり、

C言語で確保したmrubyのオブジェクトはGC対象外らしいのだが

対象にする方法があるような模様。

mrb_hash_new

int ai = mrb_gc_arena_save(mrb);

mrb_gc_arena_restore(mrb, ai);

で囲み、

GC.start

を行ってみたがメモリの使用量が変化しなかった。

関連Gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment