Crystal lang 中的哈希是否曾经在堆栈中?

Are Hashes ever on the stack in Crystal lang?

在 Crystal 语言中,Hashes 是否分配在堆栈上?或者他们总是 'heaped'?我在文档中找不到任何内容(https://crystal-lang.org/api/0.33.0/Hash.html - looked up on 19 Feb 2020). I see quite a few malloc_* in https://github.com/crystal-lang/crystal/blob/master/src/hash.cr, but wasn't sure if there was optimization I was missing. I don't think the docs call it out explicitly - did a word-find in browser for 'heap', 'stack' and 'allocate' on https://crystal-lang.org/api/0.33.0/Hash.html...找不到任何内容。

哈希总是分配在堆上。

在Crystal中,取决于对象是否为Reference or Value类型。从 Reference 继承的所有对象始终分配在堆上。

散列定义为 class Hash(K, V)。由于 class 总是继承自 Reference,哈希将始终分配在堆上。

struct Int32 这样需要堆栈分配的值类型必须定义为结构,因此它们不是继承自 Reference,而是继承自 Value.