From simon.urbanek at r-project.org  Fri Sep  9 20:00:05 2005
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Fri, 9 Sep 2005 14:00:05 -0400
Subject: [Rd] A question on R memory management in .Fortran() calls
	under Windows
In-Reply-To: <3c12769c0509091004555400f@mail.gmail.com>
References: <3c12769c0509091004555400f@mail.gmail.com>
Message-ID: <9F60C50B-7195-4F83-9048-54F0A3B66063@r-project.org>

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



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