【问题标题】:Long Vector Not Supported Yet Error in R Windows 64bit versionR Windows 64 位版本中尚不支持长向量错误
【发布时间】:2014-02-04 02:56:20
【问题描述】:

我正在尝试测试当前 R 版本的内存限制是什么。

runtest <- function(size) {
  x <- "testme"
  while(0<1) {
    x <- c(x, x)
    size <<- object.size(x)  # size of x when fail
  }
}

通过在笔记本电脑的控制台中运行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
> 

这个尺寸看起来非常接近人们之前提到的 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
>

这个 8.5GB 的限制是否与在 Windows O/S(特别是 Windows 7 企业版)中运行有关?我认为 R 帮助文件 (http://stat.ethz.ch/R-manual/R-devel/library/base/html/Memory-limits.html) 解释了这一点,但我无法理解它在说什么(不是我的专业领域)。

【问题讨论】:

  • 我不太确定“长向量”的定义是什么,但这几乎可以肯定是数据类型的限制,而不是系统内存。
  • 如果您正在寻找 64 位版本的限制,我同意链接的 Memory-limits.html 页面令人困惑。
  • 你有什么版本的 Windows,有些人为限制:msdn.microsoft.com/en-us/library/windows/desktop/…
  • 笔记本电脑和备用台式机都运行 Windows 7 Enterprise edition 64-bit

标签: r memory memory-management operating-system size


【解决方案1】:

查看size.cunique.c 的来源,用于改进object.size 的散列似乎还不支持长向量:

/* Use hashing to improve object.size. Here we want equal CHARSXPs,
   not equal contents. */

/*  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.
*/

因此,令人窒息的是object.size。不如打电话给numeric(2^36)看看能不能创建这么大的对象,(应该是64GB)。

【讨论】:

    【解决方案2】:

    最近版本的R最大向量长度是2^53-1,因为双存储模式的尾数有53位。矩阵或数组的每个维度的最大范围仍然是 2^32-1,因为维度值仍然基于整数存储模式。我想我可能会从news() 获得更多信息,但并没有我想的那么多。在 r-devel 邮件列表上有很多关于这个的讨论,如果我需要更多,我会使用 MarkMail 的存档搜索。

    ?double
    ?integer
    
    db <- news()
    str(db)
    db$Text[grepl("vector", db$Text) & grepl("length", db$Text)]
    # only slsightly informative
    db$Text[grepl("vector", db$Text) & grepl("long", db$Text)][3]
    

    [1] "支持长度超过 2^31 - 1 个元素的向量。这\n适用于原始、逻辑、整数、双精度、复数和字符\n向量以及列表。(字符向量的元素保留\n限制为 2^31 - 1 个字节。)"

    【讨论】:

      猜你喜欢
      • 2017-01-17
      • 2018-10-01
      • 2014-08-11
      • 2014-06-07
      • 1970-01-01
      • 2020-06-10
      • 2016-09-21
      相关资源
      最近更新 更多