【发布时间】:2021-08-01 20:57:23
【问题描述】:
在 Clojure 中,确定地图大小的最佳方法是什么?导入java库“java.lang.instrument.Instrumentation”并使用.getObjectSize。但是,无法导入该库。请评论如何正确导入库。
; Load the instrumentation namespace to get access to its vars
(require '[java.lang.instrument.Instrumentation :as inst])
; Find the size of an object
(println "The size of a map is"
(inst/getObjectSize {:ts 20200101170000219 :bid 108.730000 :ask 108.786000})
"bytes")
【问题讨论】:
-
使用
java.lang.instrument.*需要使Java 代理与您的程序一起运行。有an example in Clojure,但注意到getObjectSize仅报告对象的大小,不包括它所引用的对象的图形。 Andy Fingerhut 下面的回答可能会更好地满足您的需求。 -
@SteffanWestcott 感谢您的评论。我们来看看 Clojure 中的一个例子。
标签: clojure clojure-java-interop