在Eclipse中看堆gcmv使用的堆数量?(Amount used heap looking at gcmv in eclipse?)
在Eclipse中使用垃圾收集和内存可视化工具时,我不清楚我的应用程序实际需要多少内存。 看看这张图:
比如0:12它已经获得了超过0.4 GB的数据。 我知道它获得了比实际需要更多的堆(图中的堆大小)。 但我想看到的是它真正使用了多少内存。 另外两张图只是混淆了图片。 我可以在gcmv中这样做吗?
It is not clear to me how much memory my app is actually needs when I use Garbage Collection and Memory Visualizer in Eclipse. Looking at this graph:
At say 0:12 it has acquired a bit more than 0,4 GB. I know it acquires more heap (heap size in graph) than actually needs. But what I want to see is how much memory it really uses. The other two graphs just confuses the picture. Can I do that in gcmv?
原文:https://stackoverflow.com/questions/35219963
最满意答案
虽然我不确定你要用你的函数实现什么,但它不会停止的原因是因为你在无限列表上进行映射并且没有理由停止它。
无限列表源于您对
iterate
的使用:
lst = (Data.List.iterate id ([1], g_second))
你在那里做的是创建一个无限列表,其中包含无限数量的元组值
([1], g_second)
。 这似乎是一个逻辑错误 - 元组列表没有变化; 每个元素都是相同的,无穷大。 要清楚,您正在构建的列表如下所示:[([1], g_second), ([1], g_second), ([1], g_second), ([1], g_second)...]
g_second
是不变的,永远不会有理由进行评估,所以它实际上是被丢弃的。如果您使用
take
或takeWhile
类的东西,则可以强制该无限列表停止并返回已知数量的元素。 但是,通过在此声明中使用map
:map (\x -> (last (fst x))) lst
你所做的就是从元组中提取值
1
并永远重复它。由于您丢弃
g_second
并且从不使用g_first
,因此您的函数等效于以下内容:rp :: RandomGen g => g -> ([Int], g) rp g = (repeat 1 , snd (next g))
While I'm not exactly sure what you're trying to achieve with your function, the reason it doesn't stop is because you're mapping over an infinite list and giving it no reason to stop.
The infinite list originates in your use of
iterate
:
lst = (Data.List.iterate id ([1], g_second))
What you've done there is create an infinite list which contains an infinite number of the tuple value
([1], g_second)
. That seems like a logic error - that list of tuple has no variation; every element is the same, to infinity. To be clear, this list you are building looks like this:[([1], g_second), ([1], g_second), ([1], g_second), ([1], g_second)...]
g_second
is unchanging and never gets a reason to evaluate, so it is, in essence, discarded.If you were to use something like
take
ortakeWhile
, you could force that infinite list to stop and return a known number of elements. However, by usingmap
in this statement:map (\x -> (last (fst x))) lst
All you are doing is pulling the value
1
out of the tuple and repeating it forever.And since you discard
g_second
and never useg_first
, your function is equivalent to the following:rp :: RandomGen g => g -> ([Int], g) rp g = (repeat 1 , snd (next g))
相关问答
更多-
懒惰评估vs宏(Lazy Evaluation vs Macros)[2021-07-17]
懒惰评估可以替代宏的某些用途(那些延迟评估来创建控制结构的),但是相反的并不是真的。 您可以使用宏来延迟评估结构的透明度 - 请参阅SRFI 41(Streams)以获得如下示例: http : //download.plt-scheme.org/doc/4.1.5/html/srfi-std/srfi -41 / SRFI-41.html 此外,您还可以编写自己的懒惰IO原语。 然而,在我的经验中,严格语言中的普遍的懒惰代码往往会引入一个开销,相比之下,在运行时的普遍的懒惰代码,旨在从一开始就有效地支持它 ... -
为什么懒惰评估有用?(Why is lazy evaluation useful?)[2022-03-03]
主要是因为它可以更有效 - 如果不使用它们,则不需要计算值。 例如,我可以将三个值传递给一个函数,但是根据条件表达式的顺序,实际上只能使用一个子集。 在C语言中,所有三个值都将被计算出来; 但是在Haskell中,只计算必要的值。 它还允许像无限列表一样的酷的东西。 我不能在C语言中有无限列表,但是在Haskell中,这没有问题。 无数列表在数学的某些领域相当频繁地使用,所以有能力操纵它们。 Mostly because it can be more efficient -- values don't ne ... -
虽然我不确定你要用你的函数实现什么,但它不会停止的原因是因为你在无限列表上进行映射并且没有理由停止它。 无限列表源于您对iterate的使用: lst = (Data.List.iterate id ([1], g_second)) 你在那里做的是创建一个无限列表,其中包含无限数量的元组值([1], g_second) 。 这似乎是一个逻辑错误 - 元组列表没有变化; 每个元素都是相同的,无穷大。 要清楚,您正在构建的列表如下所示: [([1], g_second), ([1], g_second), ([ ...
-
懒惰的评估如何运作?(How does lazy evaluation work?)[2022-03-10]
也许这些减少可以帮助你: let x `op` y = if x > 2 then 0 else x + y test => foldr op 10 [0..] => 0 `op` foldr op 10 [1..] => 0 + foldr op 10 [1..] => 0 + (1 `op` fold ... -
懒惰的评估实施(Lazy Evaluation implementation)[2022-03-10]
对于大型数据集,懒惰评估不应该更快,它只会推迟评估,直到需要该值为止。 例如,如果你输入你的ghci : fromRange (< 50) (1, 1000000000) 在遍历整个列表之前,您必须等待一段时间,然后将其过滤并打印结果。 另一方面: take 10 $ fromRange (< 50) (1, 1000000000) 将立即完成,因为它不必计算列表的其余部分。 注意:因为它不会找到足够的条目,所以take 100也会挂起。 Lazy evaluation is not supposed ... -
用于列表处理的Haskell优化受到Lazy Evaluation的阻碍(Haskell Optimizations for List Processing stymied by Lazy Evaluation)[2022-05-25]
我不确定懒惰的评估与代码的性能有多大关系。 我认为主要问题是使用String - 这是一个链表 - 而不是更高性能的字符串类型。 请注意,您的countBetween函数中的此调用: let (topList, bottomList) = splitAt top list 将重新创建与topList相对应的链接链接, topList意味着更多的分配。 可以在此处找到用于比较splitAt与使用take n/drop n的Criterion基准: http : //lpaste.net/174526 。 ... -
RStudio和懒惰评估(RStudio and Lazy Evaluation)[2023-11-21]
当x是一个字符对象时,问题就出现了,因为在调用rlasso.formula的环境中没有定义n ,即rlasso.character()或其父项。 这大致是这样发生的: test <- function(x, ...) { UseMethod("test") } test.character <- function(x, pen = list(alpha = n)) { test.formula(x, pen = pen) } test.formula <- function(x, pen = lis ... -
Java 8 - 懒惰评估?(Java 8 - Lazy Evaluation?)[2022-05-30]
这是关键: 可组合性 arr.stream() .filter(Lazy::isGreater) .filter(Lazy::isEven) .map(Lazy::doubleIt) .findFirst(); 这似乎是无害的,但现在这是一个价值: arr.stream() .filter(Lazy::isGreater) 您可以将其交给方法并在其上构建。 什么可以用等效的循环? 您可以在任何地方使用它进行复制粘贴。 它不是一个可组 ... -
Matlab可以做懒惰的评估吗?(Can Matlab do lazy evaluation?)[2023-04-16]
据我所知,在Matlab中没有更好的方法来实现这一点, 这里也有建议 。 请记住,Matlab不会检测同一术语的多个评估。 如果你做的事情如下: foo = @() 1+1 bar=@()foo()*foo() 它将评估foo两次。 相反,“传统”方式将评估一次: foo=1+1 bar=foo+foo To my knowledge there is no better way to achieve this in Matlab, it's also suggested here. Just keep ... -
Ruby 2中的懒惰评估(Lazy evaluation in Ruby 2)[2022-03-09]
它太懒了,甚至没有做好工作 - 可能是因为你实际上没有使用操作的结果。 在那里放一个sleep()来确认: > Benchmark.bm do |rep| rep.report('lazy') { num.times do ; arr.lazy.map { |x| sleep(5) }; end } rep.report('notlazy') { 1.times do ; [0,1].map { |x| sleep(5) } ; end } end us ...