crash - Ocaml "Out of memory"异常;详细模式说 "Stack overflow in structural comparison"

标签 crash ocaml out-of-memory

需要修复来自外星来源的非常庞大的 ocaml 程序。问题之一是程序在看似无辜的行崩溃:

Hashtbl.mem loc_to_no loc

“内存不足”异常。问题是那里肯定有足够的内存,并且这条线对于其他输入来说执行得很好,甚至在处理问题的过程中更早。

使用 OCAMLRUNPARAM="v=63" 运行它,我看到在崩溃之前打印的一行:

Stack overflow in structural comparison



所涉及的结构定义如下。 loclocation 类型.
type ('a, 'b, 'c) automaton = {
  aut_id : int ;               
  mutable start_location : (('a, 'b, 'c) location) option ;
  mutable end_location   : (('a, 'b, 'c) location) option ;
  mutable aut_attributes : 'a ;                            
}
and ('a, 'b, 'c) location = {                              
  loc_id : int ;
  mutable succs : ('c * ('a, 'b, 'c) location) list ;
  mutable preds : ('c * ('a, 'b, 'c) location) list ;
  automaton : ('a, 'b, 'c) automaton ;
  mutable loc_attributes : 'b ;
}

应该怎么做才能使代码执行?

最佳答案

嗯,哈希表查找使用“=”(结构相等)来确定键是否与您要查找的键相同。结构平等需要深入检查所有子结构和东西。你有一个复杂的递归数据结构。也许在某个时候结构中有一个循环,这会导致它无限循环。在任何情况下,考虑一下您希望哈希表如何判断一个键是否与您的相同,然后您需要使用这种相等而不是默认的结构相等;使用 Hashtbl.Make仿函数来定义具有自定义相等和/或散列函数的散列表模块。

关于crash - Ocaml "Out of memory"异常;详细模式说 "Stack overflow in structural comparison",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1393233/

相关文章:

Clojure : Get "OutOfMemoryError Java heap space" when parsing big log file

android - 代码突然崩溃

Flutter 崩溃 - 致命异常 : NSInvalidArgumentException

ocaml - utop 和打印构造函数

ocaml - 没有为以下模块提供实现

奥卡姆 : Function with 'a option error

grails - Grails应用程序的内存使用情况

android - 崩溃:java.lang.NoClassDefFoundError:android.support.v7.appcompat.R$layout

debugging - 在高负载下为 ASP.NET 应用程序提供服务时,IIS 会崩溃。如何排除故障?

c++ - 错误:arma::memory::acquire():Armadillo 内存不足