lol*_*tu2 4 memory size operating-system memory-management r
我正在尝试测试当前R版本中的内存限制.
runtest <- function(size) {
x <- "testme"
while(0<1) {
x <- c(x, x)
size <<- object.size(x) # size of x when fail
}
}
Run Code Online (Sandbox Code Playgroud)
通过runtest(size)在笔记本电脑上的控制台中运行,我收到以下错误:
> runtest(size)
Error: cannot allocate vector of size 4.0 Gb
In addition: Warning messages:
1: In structure(.Call(C_objectSize, x), class = "object_size") :
Reached total allocation of 7915Mb: see help(memory.size)
2: In structure(.Call(C_objectSize, x), class = "object_size") :
Reached total allocation of 7915Mb: see help(memory.size)
3: In structure(.Call(C_objectSize, x), class = "object_size") :
Reached total allocation of 7915Mb: see help(memory.size)
4: In structure(.Call(C_objectSize, x), class = "object_size") :
Reached total allocation of 7915Mb: see help(memory.size)
> size
2147483736 bytes
>
Run Code Online (Sandbox Code Playgroud)
这个大小看起来非常接近人们之前提到的2 ^ 31-1限制.然后我尝试在我们升级的桌面上运行相同的代码,使用128GB的RAM,并将64位版本的快捷方式中的变量设置为100GB的最大内存使用量.这是我得到的新错误:
Error in structure(.Call(C_objectSize, ), class = "object_size"):
long vectors not supported yet: unique.c: 1720
> size
8589934680 bytes
>
Run Code Online (Sandbox Code Playgroud)
此8.5GB限制是否与在Windows O/S(特别是Windows 7企业版)中运行有关?我认为R帮助文件(http://stat.ethz.ch/R-manual/R-devel/library/base/html/Memory-limits.html)解释了这一点,但我无法理解它的含义(不是我的专业领域).
查看size.c和unique.c的源代码,看起来用于改进的哈希值object.size不支持长向量:
/* Use hashing to improve object.size. Here we want equal CHARSXPs,
not equal contents. */
Run Code Online (Sandbox Code Playgroud)
和
/* Currently the hash table is implemented as a (signed) integer
array. So there are two 31-bit restrictions, the length of the
array and the values. The values are initially NIL (-1). O-based
indices are inserted by isDuplicated, and invalidated by setting
to NA_INTEGER.
*/
Run Code Online (Sandbox Code Playgroud)
因此,这object.size就是窒息.如何调用numeric(2^36)以查看是否可以创建这样一个大对象(应该是64GB).