[Rd] Memory "leak" in readChar (PR#1483)
hcp@met.ed.ac.uk
hcp@met.ed.ac.uk
Mon, 29 Apr 2002 15:25:56 +0200 (MET DST)
A few days ago, I wrote
> >
> > The function readChar() appears to have some type of problem with
> >memory allocation.
On Fri, 26 Apr 2002 ripley@stats.ox.ac.uk wrote:
> It's not really a memory leak, more that R_alloc was at the time
> incorrectly documented and do_readchar needs to reset vmax.
[snip]
> I'll put the two-line fix in for 1.5.0.
I originally said that this problem didn't occur in readBin(). That seems
to be true if you are reading 8-byte data. However, I stressed this a bit
harder, and found that if you use the size=4 keyword then the problem
_does_ appear with readBin(). I enclose an example below.
Apologies if the original bug report was misleading and again, many thanks
Hugh
## Stress read/write of files in binary mode to see if there is a
## memory problem. Now, readBin seems to be innocent if the default
## (8-byte) reals are used, but there is a problem reading 4-bute reals.
nrecs <-2000
ntries <- 100
npts <- 300
gunge <- 1:npts
## Write a test file
stream <- file("/tmp/gunge")
open(stream,open="wb")
for(irec in 1:nrecs){
writeBin(gunge,"numeric",size=4)
}
close(stream)
## Read in the file ntries times. In real applications one would be reading
## ntries _different_ files and calculating some summary statistics
for(itry in 1:ntries){
stream <- file("/tmp/gunge")
open(stream,open="rb")
if(itry %% 10== 0) print(itry)
for(irec in 1:nrecs){
## Seems to be worse if reads are in several small chunks
##
bunge <- readBin(stream,"numeric",10,size=4)
bunge <- readBin(stream,"numeric",20,size=4)
bunge <- readBin(stream,"numeric",10,size=4)
bunge <- readBin(stream,"numeric",20,size=4)
bunge <- readBin(stream,"numeric",npts-60,size=4)
}
close(stream)
}
============S=u=p=p=o=r=t===D=e=b=i=a=n===http://www.debian.org============
Dr. Hugh C. Pumphrey | Tel. 0131-650-6026,Fax:0131-650-5780
Institute for Meteorology | Replace 0131 with +44-131 if outside UK
The University of Edinburgh | Email hcp@met.ed.ac.uk
EDINBURGH EH9 3JZ, Scotland | URL: http://www.met.ed.ac.uk/~hcp
============S=u=p=p=o=r=t==g=9=5==http://g95.sourceforge.net/==============
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._