iso*_*mes 3 linux memory-management r
在Windows中,只有一个可以memory.size()获取当前R会话中的(对象)占用的内存总量.
还可以了解单个对象的大小,该大小print( object.size( thing ), units='auto')表示特定数据框/表占用多少兆字节/千字节.
但是如何做到相当于print( object.size( ---workspace--- ))?
循环for (thing in ls()) print( object.size( thing ), units='auto' )打印错误的输出,例如:
64 bytes
72 bytes
88 bytes
88 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
72 bytes
88 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
64 bytes
Run Code Online (Sandbox Code Playgroud)
这不是我的意思.
正确的做法是:
for (thing in ls()) {
print(
object.size(
get(thing)
),
units='auto')
}
Run Code Online (Sandbox Code Playgroud)
这只是略有不同,因为循环用于get指定应该测量的是对象本身的大小,而不是对象的名称。
要打印整个工作区的大小,您可以尝试以下功能:
workspace.size <- function() {
ws <- sum(sapply(ls(envir=globalenv()), function(x)object.size(get(x))))
class(ws) <- "object_size"
ws
}
workspace.size()
# 35192 bytes
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2609 次 |
| 最近记录: |