[Rd] A question on R memory management in .Fortran() calls under Windows

Simon Urbanek simon.urbanek at r-project.org
Fri Sep 9 20:00:05 CEST 2005


Simone,

On Sep 9, 2005, at 1:04 PM, Simone Giannerini wrote:

> Dear R community,
>
> I have a question on how R manages memory allocation in .Fortran()  
> calls under Windows.
> In brief, apparently, it is not possible to allocate large matrices  
> inside a Fortran subroutine

I suspect that this is a problem of your compiler, not R, because it  
works without problems for me:

 > dyn.load("foo.so")
 > M=10
 > N=10
 > X=matrix(1,M,N)
 > .Fortran("foo",X,as.integer(M),as.integer(N),S=as.double(0))$S
[1] 100
 > .Fortran("foobis",as.integer(M),as.integer(N),S=as.double(0))$S
[1] 100
 > M=3000
 > N=100
 > X=matrix(1,M,N)
 > .Fortran("foo",X,as.integer(M),as.integer(N),S=as.double(0))$S
[1] 3e+05
 > .Fortran("foobis",as.integer(M),as.integer(N),S=as.double(0))$S
[1] 3e+05
 > M=10000
 > N=10000
 > X=matrix(1,M,N)
 > .Fortran("foo",X,as.integer(M),as.integer(N),S=as.double(0))$S
[1] 1e+08
 > .Fortran("foobis",as.integer(M),as.integer(N),S=as.double(0))$S
[1] 1e+08

Tested on
PC1: Win XP SP2, AMD64 3000+, 1GB RAM, gfortran 4.1.0 (20050902)
PC2: OS X, G5 1.8, 1GB RAM, gfortran 4.0.1

Cheers,
Simon



More information about the R-devel mailing list