如何在Clojure中使用.getObjectSize?

如何在Clojure中使用.getObjectSize?,clojure,clojure-java-interop,Clojure,Clojure Java Interop,在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

在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库,但请注意,Clojure中的许多集合是使用许多Java对象实现的,即通常是指向许多其他对象的“根”对象。如果您想知道所有这些的大小,和/或创建显示其结构的图形,我创建了一个名为
cljol
的库,它可以做到这一点:


自述文件显示了使用示例和您可以预期的输出。顶级自述文件中还有一个链接,指向使用库创建的其他图像库,用于一些Clojure数据结构。

使用
java.lang.instrument.*
需要使java代理与程序一起运行。尽管需要注意,
getObjectSize
只报告对象的大小,不包括它所引用的对象的图形。Andy Fingerhut下面的回答可能会更好地满足您的需要。@SteffanWestcott感谢您的评论。我们将看一看Clojure中的一个示例。感谢您的评论。cljol是阅读Clojure收藏内容的绝佳工具。在本例中,我们希望读取映射的大小,并在内存映射中使用映射的大小。