为了账号安全,请及时绑定邮箱和手机立即绑定

内存分配“错误:无法分配大小为75.1 Mb的向量”

内存分配“错误:无法分配大小为75.1 Mb的向量”

qq_笑_17 2019-11-30 14:47:39
在向量化一些仿真代码的过程中,我遇到了内存问题。我正在Windows XP下使用32位R版本2.15.0(通过RStudio版本0.96.122)。我的机器有3.46 GB的RAM。> sessionInfo()R version 2.15.0 (2012-03-30)Platform: i386-pc-mingw32/i386 (32-bit)locale:[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   [3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           [5] LC_TIME=English_United Kingdom.1252    attached base packages:[1] stats     graphics  grDevices utils     datasets  methods   base     other attached packages:[1] Matrix_1.0-6   lattice_0.20-6 MASS_7.3-18   loaded via a namespace (and not attached):[1] grid_2.15.0  tools_2.15.0这是问题的最小示例:> memory.limit(3000)[1] 3000> rm(list = ls())> gc()          used (Mb) gc trigger  (Mb)  max used   (Mb)Ncells 1069761 28.6    1710298  45.7   1710298   45.7Vcells  901466  6.9   21692001 165.5 173386187 1322.9> N <- 894993> library(MASS)> sims <- mvrnorm(n = N, mu = rep(0, 11), Sigma = diag(nrow = 11))> sims <- mvrnorm(n = N + 1, mu = rep(0, 11), Sigma = diag(nrow = 11))Error: cannot allocate vector of size 75.1 Mb(在我的应用程序中,协方差矩阵Sigma不是对角线,但是无论哪种方式,我都会得到相同的误差。)我花了整个下午阅读有关R中的内存分配问题的信息(包括here,here和here)。从我读过的书中,我得到的印象是,这与RAM本身无关,而与连续地址空间有关。不过,对我来说75.1Mb似乎很小。如果您有任何想法或建议,我将不胜感激。r 内存管理
查看完整描述

3 回答

?
月关宝盒

TA贡献1772条经验 获得超5个赞

使用栅格数据包时,我也有同样的警告。


> my_mask[my_mask[] != 1] <- NA

Error: cannot allocate vector of size 5.4 Gb

该解决方案非常简单,包括增加R的存储容量,此处为代码行:


##To know the current storage capacity

> memory.limit()

[1] 8103

## To increase the storage capacity

> memory.limit(size=56000)

[1] 56000    

## I did this to increase my storage capacity to 7GB

希望这将帮助您解决问题


查看完整回答
反对 回复 2019-11-30
  • 3 回答
  • 0 关注
  • 2794 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信